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
     
  • 相关阅读:
    Python 实例、类方法和静态方法
    allure生成测试报告,index.html页面内容为空
    【UOJ567】【IOI2020】Biscuits(DP)
    【BZOJ2410】Nim游戏(博弈论)
    【洛谷4351】[CERC2015] Frightful Formula(坐标系走路)
    【洛谷3581】[POI2015] CZA(DP)
    【LOJ117】有源汇有上下界最小流
    【洛谷6915】[ICPC2015 WF] Weather Report(哈夫曼树)
    【洛谷6152】[集训队作业2018] 后缀树节点数(SAM+LCT)
    【CF1349D】Slime and Biscuits(势能函数)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349085.html
Copyright © 2011-2022 走看看