Django 路由 命名分组

# 路由 命名分组
urlpatterns = [
    ......
    # URL地址上捕获的参数会按照 关键字传参 方式传递给试图函数
    url(r'^blogs/(?P<year>[0-9]{4})/(?P<month>\d{2})/$', views.blogs),
]

# views.py
def blogs(request, *args, **kwargs):
    print(year, type(year))
    print(month, type(month))
    return HttpResponse('Blogs')

# 结果
[28/Jul/2021 08:18:46] "GET /blogs/2022/03/ HTTP/1.1" 200 5
2022 <class 'str'>
03 <class 'str'>

 

上一篇:Django的路由系统正则匹配


下一篇:路由配置一