Django的每个项目都有一个总的urls.py
但是整个项目的所有的applications中,不同的路由全部结合在总的urls.py会很混乱;
有这样一种解决方法就是我们在每一个app里面自己编辑一个urls.py,然后在app内的urls.py里面定义自己的路由,然后总的urls.py里include每个app的urls.py文件
like this:
总的urls.py文件,包含两个app,User和Information
from django.conf.urls import include, url
from django.contrib import admin
from Home import views as Home
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^user/', include('User.urls')),
url(r'^information/', include('Information.urls')),
url(r'^$', Home.Main, name="Main"),
]
User的urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^home/(?P<User_id>[0-9]+)/$', views.UserHome, name='UserHome'),
url(r'^home/(?P<User_id>[0-9]+)/changeinfo/$', views.Changeinfo, name='Changeinfo'),
url(r'^home/(?P<User_id>[0-9]+)/changeimg/$', views.Changeimg, name='Changeimg'),
url(r'login/$', views.login, name='login'),
url(r'logout/$', views.logout, name='logout'),
]
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^(?P<Information_id>[0-9]+)/$',views.Information,name='information'),
url(r'^essayList/(?P<EssayList_page>[0-9]+)/$',views.EssayList,name="EssayList"),
url(r'edit/$', views.edit, name='edit01'),
url(r'store/$', views.store, name='edit'),
]