django 捕获的参数

捕获的参数:

被包含的URLconf会收到来自父URLconf 捕获的任何参数,所以下面的例子是合法的:

node2:/exam/mysite/mysite#cat urls.py
"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    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'^polls/', include('polls.urls', namespace='polls')),
   url(r'^books/', include('polls.urls', namespace='polls')),
   url(r'^admin/', admin.site.urls),
   url(r'^contact/', include('polls.urls',namespace='aaa')),
   url(r'^(?P\w+)/blog/', include('polls.urls',namespace='bbb')),
]



node2:/exam/mysite/polls#cat urls.py
from django.conf.urls import url,include

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    # ex: /polls/5/
    url(r'^(?P[0-9]+)/$', views.detail, name='detail'),
    # ex: /polls/5/results/
    url(r'^(?P[0-9]+)/results/$', views.results, name='results'),
    # ex: /polls/5/vote/
    url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'),

    url(r'^articles/2003/$', views.special_case_2003),
    url(r'^articles/(?P[0-9]{4})/$', views.year_archive),
    url(r'^articles/(?P[0-9]{4})/(?P[0-9]{2})/$', views.month_archive),
    url(r'^articles/(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})/$', views.article_detail),
    
    url(r'^articles/page(?P[0-9]?)/$', views.page),

    url(r'^change/(?P[0-9]{4})/$', views.change),
    url(r'^archive/$', views.archive), 
   
    
]


view:

def archive(req,username):
  print username
  return HttpResponse(username)

  
http://192.168.137.3:8000/dsdsds/blog/archive/
dsdsds
 

 

你可能感兴趣的:(Django1.8文档)