In Python, urls. py: URL dispatcher (routing configuration file) details,
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<id>\d{2})/$', views.test)url(r'test2/(?P<id>\d{2})/(?P<key>\w+) /$', views.test)
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!