Django 路由分发
当一个url请求过来之后
1、先到项目主目录下的urls内。
2、由这个url做处理分发给其他app内的urls。
一级路由:主目录urls内引入include
from django.conf.urls import url,include urlpatterns = [ # 指定分发的app目录名称 url(r‘^cmdb/‘,include("app01.urls")), url(r‘^monitor/‘,include("app02.urls")), ]
二级路由:只查找本地urls内的路径
from django.conf.urls import url,include from app01 import views urlpatterns = [ url(r‘^login/‘, views.login), ]
其他路由方案
urlpatterns = [ url(r‘^admin/‘, admin.site.urls), url(r‘^business$‘, views.business), #url(r‘^business_add‘, views.business), ]
加入终止符 $、避免business_add 被截胡
原文地址:https://www.cnblogs.com/xiangsikai/p/10917795.html
时间: 2024-10-08 02:33:07