Django finishing (b) - the preliminary view and use templates

In Django view

    · Django views to write web applications using business logic

    · Django view that is a function that can be called a view function

    · View definition file in the application view.py

    · View need to bind a URL address (routing) can be found Django framework and called for execution

 

A preliminary view of use

    Demand: Write view and configure the URL (routing), to achieve a display interface

        1. Demand: When a browser to access the URL http: //127.0.0: When 8000 / users / index, display hello django information

        2. To achieve:

              i. need to write a view function

              ii. configure access route for this view

    1. Create a view

        Open users module you just created, written in the code view in views.py.  

        

        

        Notes view:

            · About view

                i. The view is not called by the developer initiative, but called by Django framework

                ii. Django When receiving the request, will perform regular URL matches a corresponding call view

                The first parameter iii. When calling view, Django will request information is encapsulated as a HttpRequest object, and as a view incoming

            · Parameters on view

                i. The first parameter view must be defined, customizable name, but the name is used to request, type HttpRequest

                ii. the absence of this parameter, Django calls the view at the time, the object will not be passed Httprequest

            · The return value on a view

                i. HttpResponse must return a view object (object or subclasses)

                ii. HTTPRequest requested object is created by Django, HttpResponse response object created by the developer       

    2. Configure URL (routing)  

        · Conduct url routing urls.py file in the project configuration is as follows:

          

    3. Test your browser

        Http://127.0.0.1:8000/users/index enter the URL in your browser to confirm whether the logical view of information returns hello django

        

Guess you like

Origin www.cnblogs.com/ljfight/p/11209221.html