• 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
     
  • 相关阅读:
    基于AJAX的长轮询(longpolling)方式实现简单的聊天室程序
    WPF笔记(1.4 布局)——Hello,WPF!
    WPF笔记(1.10 绘图)——Hello,WPF!
    The description of GameHall and my program experience for interview
    SQL大量数据操作 切身经验总结
    WPF笔记(1.6 数据绑定)——Hello,WPF!
    WPF笔记(1.8 资源与映射)——Hello,WPF!
    WPF笔记(2.3 StackPanel)——Layout
    WPF笔记(2.2 DockPanel)——Layout
    Description of AJAX
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349085.html
Copyright © 2020-2023  润新知