zoukankan      html  css  js  c++  java
  • 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<username>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<question_id>[0-9]+)/$', views.detail, name='detail'),
        # ex: /polls/5/results/
        url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
        # ex: /polls/5/vote/
        url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
    
        url(r'^articles/2003/$', views.special_case_2003),
        url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),
        url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', views.month_archive),
        url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.article_detail),
        
        url(r'^articles/page(?P<num>[0-9]?)/$', views.page),
    
        url(r'^change/(?P<year>[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
     
  • 相关阅读:
    __del__ 析构方法 __init__ 构造方法
    单态模式
    面向对象小练习2
    __new__ '''魔术方法
    菱形继承
    继承:多继承
    继承: .单继承
    面向对象小练习
    __init__ 魔术方法
    如何访问私有成员
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349085.html
Copyright © 2011-2022 走看看