Django 路由分发
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), ]
# 后面加入第三个参数,参数名称为indexx。 path('infdafddsfadsafdsafdsfdasfdsdex/', views.index,name='indexx') # <!-- 引用url返回的路径变量,直接引用form表单内 --> <form action="{% url 'indexx' %}" method="POST">