mysite/news/urls.py:
from django.conf.urls import URL from . import Viewsurlpatterns = [URL (r '
The above code maps the URLs map to a Python callback function (view) as a simple regular expression. the regular expression "captures" the value in the URLs by means of parentheses. When a user requests a page, Django will match each pattern in order and stop at the URL of the first matching request. (if there is no match, Django calls a special 404 view.) the entire process is extremely fast because the regular expression is compiled at load time.
once a regular expression is matched, Django will import and invoke the corresponding view, which is actually a simple Python function. Each view will have a request object-it contains the meta-information of the request-and the value captured by the regular expression.
For example, if a user requests the URL "/articles/2005/05/39323/", Django will call the function News.views.article_detail (Request, ' 2005 ',' ', ' 39323 ').
In news.views.py:
def article_detail (request,year, month, number):
......
Call "/articles/2005/05/39323/?day=monday", and the argument is worth the corresponding relationship:
Request. get[' Day '] = = ' Monday '
Year = = 2005
month = = 05
Number = = 39323
Django URL Design Trivia Point