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.浏览器访问后
标签:匹配,views,URL,py,视图,app01,urls,test,import 来源: https://blog.51cto.com/jackor/2757845