Django的url路由系統簡介

2022-05-10 01:24:09 字數 1959 閱讀 4057

from

django.conf.urls import url

from

django.contrib import admin

urlpatterns =[

url(r

'^admin/

', admin.site.urls),

]

from

django.conf.urls import url

from

django.contrib import admin

from

django.conf.urls import include

urlpatterns =[

url(r

'^admin/

', admin.site.urls),

url(r

'', include("

")),

url(r

'', include("

")),

]

from

django.conf.urls import url,include

from

django.contrib import admin

from

urlpatterns =[

url(r

'^admin/

', admin.site.urls),

url(r

'^index/

', views.index),

]

from

django.conf.urls import url,include

from

django.contrib import admin

from

urlpatterns =[

url(r

'^admin/

', admin.site.urls),

url(r

'^index/

', views.index, name='別名'

),]

from

django.conf.urls import url,include

from

django.contrib import admin

from

urlpatterns =[

url(r

'^admin/

', admin.site.urls),

url(r

'^index/(\w+).html$

', views.index),

]

"""

url別名是django才有的特性,通用標準還是在後端生成url再傳遞給html

"""可以通過reverse反向查詢url,在資料庫層面則根據不同使用者許可權儲存url別名

:param request:

:return:

"""#

1.在這裡可以直接查詢資料庫獲取url別名,然後傳入render()

url_list =[

'url_one

','url_two

','url_three']

#2.url = reverse("url_one") # 也可以通過別名直接反向獲取url然後傳入render()

return render(request, '

index.html

', )

"en

">

"">c1

Django的路由系統 URL

基本格式 from django.conf.urls import url urlpatterns url 正規表示式,views檢視,引數,別名 django 2.0版本的路由系統 from django.urls import path,re path urlpatterns path arti...

Django之(URL)路由系統

簡而言之,django的路由系統作用就是使views裡面處理資料的函式與請求的url建立對映關係。使請求到來之後,根據urls.py裡的關係條目,去查詢到與請求對應的處理方法,從而返回給客戶端http頁面資料 django 專案中的url規則定義放在project 的urls.py目錄下,預設如下 ...

Django基礎二之URL路由系統

基本格式 from django.conf.urls import url 迴圈urlpatterns,找到對應的函式執行,匹配上乙個路徑就找到對應的函式執行,就不再往下迴圈了,並給函式傳乙個引數request,就是請求資訊的所有內容 urlpatterns url 正規表示式,views檢視函式,...