例:
urls.py
a. '^index/' views.index
b. r'^index/(\d+)', views.index
c. r'^index/(?P<nid>\d+)', views.index, {'name':'root'}
d. r'^index/(?P<nid>\d+)', views.index, {'name':'root'}, name='index'
views.py
c. def index(request, name,nid):
#urls.py可以传个默认值name
pass
d. def index(request, name, nid):
#反解URL(拼接成URL)
reverse('index',kwargs={'nid':1}) ----> /index/1
{% url 'index' 1 %} ----/index/1
命名空间
#主urls.py
/admin/ include('app01.urls',namespace='m1')
/crm/ include('app01.urls',namespace='m2')
#副mrls.py
app_name='app01' <<<---------------------------注意!----------------------------
/index/ name = 'n1'
/xxx/(?P<pk>\d+)/ name = 'n2'
#################
#views.py中
v1 = reverse('m1:n1') -----> /admin/index/
v2 = reverse('m2:n1') -----> /crm/index/
v3 = reverse('m2:n2',kwargs={'pk',1}) ------>/crm/xxx/1/ <-----------注意!-------
#template中
{% url 'm1:n1' %} ---->/admin/index/