Django如何实现路由分发[Django框架]
路由的分发 include
主程序的URL中,导入include
from django.conf.urls import url,include#app用两个分别叫(luyou,luyou1)
urlpatterns = [
url(r'^cmdb/', include('luyou.urls')),
url(r'^monitor/',include('luyou1.urls')),
]
app---------luyou的URL中(创建app的命令: python manage.py startapp luyou)
from luyou import viewsurlpatterns = [
url(r'^index/', views.index),
]
luyou对应views.py中
def index(request):
return HttpResponse('luyou')
另一个app---------luyou1的URL中(创建app的命令: python manage.py startapp luyou1)
相关推荐:《Python相关教程》
from luyou1 import viewsurlpatterns = [
url(r'^index/', views.index),
]
luyou1对应views.py中
def index(request):
return HttpResponse('luyou1')
预期
相关推荐:
Django如何进行urls映射管理
以上是 Django如何实现路由分发[Django框架] 的全部内容, 来源链接: utcz.com/z/539575.html