view view of the control data returned django view function

View View eight. 
Overview: python views.py defined function that accepts a response back to the Web and Web requests. 
There are several pages there are several views View 
the User access url address to send request ---> urls scheduler match ----> views to get the data model ----> model processing ----> views attempt to respond data return ---> Template ---> user 
to configure routing project, the application under the new urls.py 
urls.py under 1. modify the project 
use: regular Home urls matching server dispatcher 
from django.conf.urls import url , the include 
the urlpatterns = [ 
    URL ( 'ADMIN /', admin.site.urls), 
    URL (R & lt '^', the include ( "app.urls")), 
] 
to enter the index view function views.py new applications: 
for Home view function New: 
#from django.shortcuts Import the render 
# the Create your views here Wallpaper. 
from django.http HttpResponse Import 
Import json 
DEF index (Request): 
    Data = { "User": "test001", "
    = json.dumps JS (Data) 

2. In a new application into the directory urls.py, and modify the configuration: 
from django.conf.urls Import URL 
from Import views. 
the urlpatterns = [ 
   URL (R & lt '^ $', views .index) 
] 
URLs match numbers: 
views view New function: 
DEF jobDetail (Request, NUM, num2): 
    return the HttpResponse ( "the IS THIS TESTS Detail of the REQUEST NUM {}, {}" the format (NUM, num2.)) 

    URL ( R & lt '^ (\ + D) / (\ + D) / $', views.jobDetail), 
   Web requests: http://127.0.0.1:8000/22/222/ digital passed through the regular matching view function 
   returns: 
   THIS IS TESTS REQUEST num of detail 22,222

  

Guess you like

Origin www.cnblogs.com/SunshineKimi/p/11757565.html