标签:
(1)Including other URLconfs
比如一个website项目urls.py, include了其他的urls:
from django.conf.urls import include, url urlpatterns = [ # ... snip ... url(r‘^community/‘, include(‘django_website.aggregator.urls‘)), url(r‘^contact/‘, include(‘django_website.contact.urls‘)), # ... snip ... ]
注意include之前的正则表达式没有终止符 $ 而是 /
当调用clude时,把url前边正则表达式匹配到的chop off(砍掉),剩下的string传递到include的urls中进行进一步操作。
另一个例子
from django.conf.urls import include, url from apps.main import views as main_views from credit 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)), ]
该例中 url: credit/reports/ 对应的方法是credit_views.report
标签:
原文地址:http://www.cnblogs.com/LuoDa/p/5406912.html