对于一个大的工程,可能会有很多应用,比如cmbd,moniter,openstack等等,我们就要用到路由分发
1,首先在跟工程同名的文件夹下的urls中写分发表:
from django.conf.urls import url,include urlpatterns = [
url(r'^app01/',include('app01.urls')),
url(r'^app02/',include('cmbd.urls')),
]
2,在各应用app里创建urls.py并写上自己的路由分发:
from app01 import views
from django.conf.urls import url
urlpatterns = [
url(r'^home/', views.home),
]
from django.contrib import admin
from django.urls import path
from cmbd import views
from django.conf.urls import url
urlpatterns = [
path('admin/', admin.site.urls),
path('home/', views.home),
path('detail',views.detail),
]
这样访问/app01和/app02的目录就分到了各自的应用上,而且各自的二级uri也可以一样