• Django框架路由的include分发机制


    """mysite URL Configuration

    The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
    Examples:
    Function views
    1. Add an import: from my_app import views
    2. Add a URL to urlpatterns: path('', views.home, name='home')
    Class-based views
    1. Add an import: from other_app.views import Home
    2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
    Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
    """
    from django.contrib import admin
    from django.urls import path,re_path,include
    from views.py import get_ncov,article,articleByMonth,get_timer,test
    urlpatterns = [
    #urls路由控制器
    path('article/2012', article),
    re_path('article/\d+', article),
    re_path('^article/\d+$', article),
    re_path('^article/\d{4}$', article),
    #无名分组
    # /article/2012
    re_path('^article/(\d{4})$', article), # article(request,2012)
    # /article/2012/12
    re_path('^article/(\d{4})/\d{1,2}$', articleByMonth), # articleByMonth(request,2012,12)

    #有名分组
    re_path('^article/(?P<year>\d{4})/(?P<month>\d{1,2}$', articleByMonth), # articleByMonth(request,year=2012,month=12)


    #路由的include分发机制
    path('app01/', include('app01.urls')),

    #path('app01/admin/', admin.site.urls),
    #path('app01/timer/', get_timer),
    #path('app01/test/', test),
    #path('app01/2019ncov/', get_ncov),

    '''
    re.findall('article/\d+',"article/2011abc")
    re.findall('article/\d+',"abc/article/2011abc")
    re.findall('article/\d+',"abc/article/abc/2011abc")
    '''

    ]
    """mysite URL Configuration

    The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
    Examples:
    Function views
    1. Add an import: from my_app import views
    2. Add a URL to urlpatterns: path('', views.home, name='home')
    Class-based views
    1. Add an import: from other_app.views import Home
    2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
    Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
    """
    from django.contrib import admin
    from django.urls import path,re_path
    from views.py import get_ncov,article,articleByMonth,get_timer,test
    urlpatterns = [

    path('admin/', admin.site.urls),
    path('timer/', get_timer),
    path('test/', test),
    path('2019ncov/', get_ncov),


    ]
  • 相关阅读:
    WordPress网站绑定多个域名的方法
    htpasswd 命令使用
    在Windows下用OpenSSL生成证书步骤
    WCF中关于List和数据的转换问题
    NET2.0的配置文件
    C# Attribute
    c#自定义属性
    VS2005中读写配置文件(方法二)
    c#的反射
    Asp.NET 操作配置文件 Steven Pei 博客园
  • 原文地址:https://www.cnblogs.com/A121/p/16448644.html
Copyright © 2020-2023  润新知