This article mainly introduces urls in Python. py: URLdispatcher (route configuration file) detailed information, you can refer to this article to learn about urls in Python. py: detailed description of URL dispatcher (route configuration file). For more information, see
Urls. py: URL dispatcher (route configuration file)
URL configuration (URLconf) is like the Directory of the website supported by Django. It is essentially a ing table between the URL mode and the view functions to be called for this URL mode. In this way, tell Django to call this code for this URL, and call that code for that URL. Url loading starts from the configuration file.
Urlpatterns
List used if no prefix exists (recommended)
URL mode
Urlpatterns = [url (regular expression, view function, parameter, alias, prefix),]
Parameter description:
Regular expression: Regular expression
View function: a Callable object, usually a view function or a string that specifies the path of the view function.
Parameters: optional default parameters to be passed to the View function (dictionary form)
Alias: an optional name parameter
Prefix: path prefix
URL splitter
Generally, a URL parser corresponds to a URL configuration module. it can contain multiple URL modes or multiple other URL resolvers. Through this design of the include structure, Django can parse the UR hierarchy.
The URL parser is the key for Django to decouple apps from projects. Generally, the URL configuration module operated by the include method will be diet into a URL splitter.
Common URL syntax example regex
url(r'test/\d{2}/$', views.test) # test/66url(r'test/(?P
\d{2})/$', views.test)url(r'test2/(?P
\d{2})/(?P
\w+) /$', views.test)
Thank you for reading this article. I hope it will help you. thank you for your support for this site!
The above is the detailed introduction of urls. py: URL dispatcher (route configuration file) in Python. For more information, see other related articles in the first PHP community!