Django의 URL 루트 시스템 (관계 매핑,name 값, 루트 배달, 기본값, 이름 공간 namespace) [인터랙티브 편1]
카탈로그
하나.URL 라우팅 매핑 관계식둘.url 루트의name값 셋.URL 라우팅 배포넷.기본값오.네임스페이스namespace하나.URL 라우팅 매핑 관계
실전 Django의 URL 라우팅 매핑 관계:https://blog.csdn.net/Burgess_zheng/article/details/86528727
1. (정적 URL) 하나의 URL은 하나의 실행 함수나 실행 클래스에 대응한다.
FBV:
path('burgess_web/', views.func),# Django path
url(r'^burgess_web/', views.func), #2.0 url
# url views func
CBV:
path('burgess_web/', views.Class.as_view()), # Django path
url(r'^burgess_web/', views.Class.as_view()), #2.0 url
# url views Class( djangon )
2.( url) url
FBV:
# url
#1.
re_path('burgess01-(\d+)-(\d+).html/', views.test01), # Django path
#url(r'^burgess01-(\d+)-(\d+).html/', views.test01), #2.0 url
#2.
re_path('burgess02-(?P\d+)-(?P\d+).html/', views.test02), # Django path
#url(r'^burgess02-(?P\d+)-(?P\d+).html/', views.test02), #2.0 url
#
re_path('burgess03-(?P\d+)-(?P\d+).html/', views.test03), # Django path
# url(r'^burgess03-(?P\d+)-(?
# url 3
def test01(request,*args):
print(args)
return HttpResponse('args:%s'%json.dumps(args))
def test02(request,*args,**kwargs):
print(kwargs)
return HttpResponse('kwargs:%s'%json.dumps(kwargs))
def test03(request,nid,uid):
print(nid,uid)
return HttpResponse('nid:%s,uid:%s' %(uid,nid))
CBV: FBV
.url name
Django URL name :https://blog.csdn.net/Burgess_zheng/article/details/86529185
name ? url
1.html( ) name url ( )
1.{% url 'indexx' 2 6 %}
URL:
re_path('burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01'),# Django path
#url(r'^burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01'), #2.0 url
Templates:
{% url 'burgess01' 2 6 %} # url
burgess01 == burgess01-(\d+)-(\d+).html # url
'burgess01' 2 6 == burgess01-2-6.html
# url:burgess01-13-16.html
# url render
#render html {% url 'burgess01' 2 6 %} == burgess01-2-16.html
2.{{ request.path_info }}
URL:
re_path('burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01'), # Django path
#url(r'^burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01'), #2.0 url
Templates:
{{ request.path_info }} # url
request.path_info ==burgess01-(\d+)-(\d+).html # url
# url:burgess01-1-2.html
# url render
#render html { request.path_info }} == burgess01-1-2.html
2.func name url ( )
1.
URL:
re_path('burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01'), # Django path
#url(r'^burgess01-(\d+)-(\d+).html/', views.test01,name='burgess01') #2.0 url
FUNC:
def test01(request,*args):
from django.urls import reverse # url
names = reverse('burgess01', args={90,88,}) # url
print(names)
return render(request,'burgess.html',{'names':names}) # , html
2.
URL:
re_path('burgess02-(?P\d+)-(?P\d+).html/', views.test02,name='burgess02'),
#url(r'^burgess02-(?P\d+)-(?P\d+).html/', views.test02,name='burgess02'),
FUNC:
def index(request,nid,uid):
from django.urls import reverse
names = reverse('burgess02',kwargs={"nid":80,"uid":90})
print(names)
return render(request,'burgess.html',{'names':names}) # , html
.URL
Django URL :https://blog.csdn.net/Burgess_zheng/article/details/86529768
app , app urls.py , 。
: ,Monitor( ) , cmdb , 2 urls.py ., ( )
: , ,Monitor ,openstyle..
project(urls.py):
from django.contrib import admin
from django.urls import path,re_path #Django 2.0
from django.conf.urls import url #Django2.0
from django.conf.urls import include
urlpatterns = [
path('admin/', admin.site.urls),
#
#cmdb_app
re_path('cmdb/',include("cmdb.urls")),
#url(r'^cmdb/', include("cmdb.urls")),
#monitor_app
re_path('monitor/', include("monitor.urls")),
# url(r'^monitor/', include("monitor.urls")),
]
app(urls.py):
from django.urls import path,re_path #Django 2.0
from app_name import views
from django.conf.urls import url #Django2.0
from django.conf.urls import include
urlpatterns = [
re_path('',views.burgess_func),
#url(r'',views.burgess_func),
]
.
url , ,url
#URL
from django.contrib import admin
from django.urls import path,re_path #Django 2.0
from project_burgess import views
from django.conf.urls import url #Django2.0
urlpatterns = [
path('admin/', admin.site.urls)
re_path('xxx/', views.func,{'name':'root'}), #{'name':'root'}: ==
#url(r'^xxx/', views.func,{'name':'root'}), #{'name':'root'}: ==
]
#URL
from django.shortcuts import render,HttpResponse,redirect
def func(requst,name): #name : url
return HttpResponse('name')
. namespace
Django URL :https://blog.csdn.net/Burgess_zheng/article/details/86530913
URL URL
# URL
from django.contrib import admin
from django.urls import path,re_path #Django 2.0
from project_burgess import views
from django.conf.urls import url #Django2.0
from django.conf.urls import include
urlpatterns = [
path('admin/', admin.site.urls)
# namespace
re_path('a/',include("namespace.urls", namespace='author')),
#url(r'^a/', include("namespace.urls", namespace='author')),
re_path('b/',include('namespace.urls', namespace='publisher')),
#url(r'^b/', include('namespace.urls', namespace='publisher')),
]
# URL(app )
__author__ = "Burgess Zheng"
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from django.urls import path,re_path #Django 2.0
from namespace import views
from django.conf.urls import url #Django2.0
app_name='namespace'
urlpatterns = [
re_path('index/',views.index,name='index'),
#url(r'^index/', views.index,name='index'),
]
#URL +name URL
from django.shortcuts import render,HttpResponse,redirect
# Create your views here.
def index(request):
from django.urls import reverse # URL name url
a = reverse('author:index') # url url
print(a)# 127..../a/index/
b = reverse('publisher:index') # url url
print(b)# 127..../b/index/
return HttpResponse('a:%s b:%s'%(a,b))
:Django 【 】
:Django
:Django view 【 】
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django 라우팅 계층 URLconf 작용 및 원리 해석URL 구성(URLconf)은 Django가 지원하는 웹 사이트의 디렉토리와 같습니다.그것의 본질은 URL과 이 URL을 호출할 보기 함수 사이의 맵표입니다. 위의 예제에서는 URL의 값을 캡처하고 위치 매개 변수로...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.