Typically there will be a root_urlconf in settings.py, and Django will look for a route from the root_urlconf point to the file that the Urlpatterns variable is configured for.
Urlpatterns can also include urlpatterns in other model, Django will find from top to bottom to see if the URL matches. After matching, the corresponding view processing is given.
Urlpatterns = [ url (r'^admin/', include (Admin.site.urls)), URL (r '^index/$', view_index), URL (r'^blog/ ' , include (Blog_urls)),]
The non-named capturing group in the URL is received in the view with the position parameter, actually receives the tuple, you receive the same with *args, the tuple will automatically unpack to the corresponding location
Urlpatterns = [ url (r'^articles/([0-9]{4})/$', views.year_archive), URL (r'^articles/([0-9]{4})/([0-9]{2})/$', views.month_archive),]
def month_archive (request, year, month): Pass
The named capturing group is received with the keyword parameter, actually receives a dictionary, the dictionary will automatically unpack to the corresponding field, you receive with **kw and then own solution is same
Urlpatterns = [ url (r'^articles/(? P<YEAR>[0-9]{4})/$', views.year_archive), URL (r'^articles/(? P<YEAR>[0-9]{4})/(? P<MONTH>[0-9]{2})/$', views.month_archive),]
def month_archive (request, year, month): Pass
All parameters are received as strings, regardless of the type in your regular (captured arguments is always strings)
This place in development encountered several pits, the background RPC interface received is shaping, and I passed the string, resulting in an incorrect sorting, also thought that there is a problem with the RPC interface, the level of the dish.
Override the default 404 500 Interface, just assign a custom view to django.conf.urls.handler404 in root_urlconf
django.conf.urls.handler404 == view_500
Reverse URL, to Reverse a URL first name
Non-named parameter reverse
Urlpatterns = [ url (r'^articles/([0-9]{4})/$', view_articles, Name=' article')]print(reverse ('article') , args= (2015,)))
Named parameter reverse
defview_articles (Request, year):returnHttpResponse (content='Hello World') Urlpatterns=[url (r'^articles/(? P<YEAR>[0-9]{4})/$', View_articles, Name='article')]Print(Reverse ('article', kwargs={' Year': 2018}))
Django Notes II: URL Dispatcher