Django如何实现路由分发
爱喝马黛茶的安东尼
2019-07-01 16:50:412835浏览 · 0收藏 · 0评论
路由的分发 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 views urlpatterns = [ 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 views urlpatterns = [ url(r'^index/', views.index), ] luyou1对应views.py中 def index(request): return HttpResponse('luyou1')
预期
相关推荐:
关注公众号,随时随地在线学习