Django 使用正则匹配URL 并将匹配成功的值传递给视图函数

1.项目urls.py
from django.conf.urls import url, include

urlpatterns = [
    url(r‘^‘, include(‘app01.urls‘, namespace=‘app01‘)),
]

2.app01.urls.py

from django.conf.urls import ur
from . import views

app_name = ‘app01‘
urlpatterns = [
    url(r‘tiaozhuan/(?P<username>\w+)/$‘, views.test, name=‘test‘),
]

3.app01.views.py

from django.http import HttpResponse
def test(request, username):
    print(username)
    return HttpResponse(‘test‘)

4.浏览器访问后
Django 使用正则匹配URL 并将匹配成功的值传递给视图函数
Django 使用正则匹配URL 并将匹配成功的值传递给视图函数

Django 使用正则匹配URL 并将匹配成功的值传递给视图函数

上一篇:php头条,PHP实现新闻头条操作


下一篇:http client SunCertPathBuilderException unable to find valid certification path to requested target