Django Notes urls.py Detailed

Source: Internet
Author: User

Urls.py:URL Distributor (Routing profile)

The URL configuration (URLconf) is like the directory of the Web site that Django supports. Its essence is the URL pattern and the mapping table between the view functions to invoke for that URL pattern. That's how you tell Django to call that code for that URL and call that code for that URL. The loading of the URL begins in the configuration file.

When you execute django-admin.py startproject , the script automatically builds a copy of the URLconf (that is, the urls.py file) for you. In a settings.py file that is automatically created at the same time, create a variable root_urlconf whose value is the module name of the root URLCONF. The default value is the module name of the urls.py file.

For example: The root of my Django project is named "Hello_django" and the default value for root_urlconf is "Hello_django.urls".

Urlpatterns two different forms:

The first type:

The second (new version of Django is deprecated):

URL pattern:

Urlpatterns = [

URL (regular expression, views function, parameter, alias, prefix)

]

Source:

URL (r ' ^hello/$ ', Views.hello)
The form of the object can be written as a string: URL (r ' ^hello/$ ', ' Hello.views.hello ')


Django Notes urls.py Detailed

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.