(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 ()