Django URL Management--include ()

Source: Internet
Author: User

(1) including other Urlconfs

For example, a website project urls.py, including other URLs:

From Django.conf.urls import include, urlurlpatterns = [    # ... snip    ... URL (r ' ^community/', include (' Django_website.aggregator.urls ')),    URL (r ' ^contact/', include (' Django_ Website.contact.urls '),    # ... snip ...]

Note that the regular expression before include does not have a terminator $ but/

When Clude is called, the chop off that matches the regular expression in front of the URL is removed, and the remaining string is passed to the include URLs for further action.

Another example

From Django.conf.urls import include, Urlfrom Apps.main import views as Main_viewsfrom Credits import views as Credit_views Extra_patterns = [    url (R ' ^reports/$ ', credit_views.report),    url (r ' ^reports/(? p<id>[0-9]+)/$ ', credit_views.report),    url (r ' ^charge/$ ', credit_views.charge),]urlpatterns = [    URL (r ' ^$ ', main_views.homepage),    url (r ' ^help/', include (' Apps.help.urls ')),    URL (r ' ^credit/', include (Extra_ patterns)),]

In this case, the corresponding method of url:credit/reports/is Credit_views.report

Django URL Management--include ()

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.