Django的路由分发与名称空间
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
路由分发django每一个app下面都可以有自己的urls.py路由层,templates文件夹,static文件夹项目名下urls.py(总路由)不再做路由与视图函数的匹配关系而是做路由的分发from django.conf.urls import include# 路由分发 注意路由分发总路由千万不要$结尾url(r'^app01/',include(app01_urls)),url(r'^app02/',include(app02_urls))# 在应用下新建urls.py文件,在该文件内写路由与视图函数的对应关系即可from django.conf.urls import urlfrom app01 import viewsurlpatterns = [url(r'^index/',views.index)]名称空间(了解)url(r'^app01/',include(app01_urls,namespace='app01')),url(r'^app02/',include(app02_urls,namespace='app02'))
或
url(r'^app01/' include(app01.urls),app01.urls.pyfrom django.conf.urls import urlfrom app01 import viewsurlpatterns = [url(r'^index/',views.index,name='index')]
#或取名字时取独一无二的,这样就不会有冲突app02.urls.pyfrom django.conf.urls import urlfrom app02 import viewsurlpatterns = [url(r'^index/',views.index,name='index')]app01.views.pyreverse('app01:index')app02.views.pyreverse('app02:index')