In Python, urls. py: URL dispatcher (routing configuration file) details,

Source: Internet
Author: User

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:

  1. Regular Expression: Regular Expression
  2. View function: a callable object, usually a view function or a string that specifies the path of the view function.
  3. Parameters: Optional default parameters to be passed to the view function (Dictionary form)
  4. Alias: an optional name parameter
  5. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.