django路由之分發子應用

2021-08-07 03:53:08 字數 2078 閱讀 4657

接上篇 針對url過多的問題 可以把各個url分發到各個應用下的urls

專案下的

urls

"""dajon_demo url configuration

the `urlpatterns` list routes urls to views. for more information please see:

examples:

function views

2. add a url to urlpatterns: url(r'^$', views.home, name='home')

class-based views

2. add a url to urlpatterns: url(r'^$', home.as_view(), name='home')

including another urlconf

1. import the include() function: from django.conf.urls import url, include

2. add a url to urlpatterns: url(r'^blog/', include('blog.urls'))

"""from django.conf.urls import url, include

from django.contrib import admin

urlpatterns = [

url(r'^admin/', admin.site.urls),

# url(r'^index/', views.index),

# url(r'^login_in/', views.login_in),

# #有名分組

## url(r'^articles/(?p\d)/(?p\d)$', views.year_month),

## # 無名分組 傳參 ()中為引數 類似re.findall

# url(r'^articles/(\d)$',views.year),

# url(r'^articles/(\d)/(\d)', views.month),

]

應用下的urls

"""dajon_demo url configuration

the `urlpatterns` list routes urls to views. for more information please see:

examples:

function views

2. add a url to urlpatterns: url(r'^$', views.home, name='home')

class-based views

2. add a url to urlpatterns: url(r'^$', home.as_view(), name='home')

including another urlconf

1. import the include() function: from django.conf.urls import url, include

2. add a url to urlpatterns: url(r'^blog/', include('blog.urls'))

"""from django.conf.urls import url, include

from django.contrib import admin

urlpatterns = [

url(r'^index/', views.index),

url(r'^login_in/', views.login_in),

#有名分組

url(r'^articles/(?p\d)/(?p\d)$', views.year_month),

# 無名分組 傳參 ()中為引數 類似re.findall

url(r'^articles/(\d)$',views.year),

url(r'^articles/(\d)/(\d)', views.month),

]

Django 路由分發

django 路由分發 當乙個url請求過來之後 1 先到專案主目錄下的urls內。一級路由 主目錄urls內引入include from django.conf.urls import url,include urlpatterns url r cmdb include url r monitor...

Django路由分發

1.路由匹配,urls.py中 url r testadd views.testadd 匹配規則 從上到下只要正規表示式匹配成功,就不會往下匹配了 get請求的傳參方式?無名分組 url r test d views.test 會把括號中匹配的數字當成位置引數傳給檢視函式 有名分組 url r te...

django路由系統及分發路由的本質

當我們啟動乙個django專案後,想要通過瀏覽器訪問到django專案中的資源 就需要在django中的urls專案中進行路由配置 urlpatterns url r admin admin.site.urls url r test test1 這樣就可以在瀏覽器訪問到jango中的函式 然而在這個...