python-Django中的网址模式正则表达式
作者:互联网
这是一个基本问题,但是我在文档中找不到答案:
可以说我有一个网址,例如:
http://example.com/part1/part2
我有:
urlpatterns = patterns('',
# Examples:
url(r'^$', 'xxx', name='yyy'),
)
上面的url字符串的哪一部分试图被^和$之间的正则表达式匹配?
我已经阅读了许多资料和文档,包括:
> https://docs.djangoproject.com/en/1.6/intro/tutorial03/
> https://docs.djangoproject.com/en/1.6/ref/urlresolvers/#module-django.core.urlresolvers
> http://www.djangobook.com/en/2.0/chapter03.html.
解决方法:
在documentation中明确指出:
The URLconf searches against the requested URL, as a normal Python
string. This does not include GET or POST parameters, or the domain
name.For example, in a request to 07001, the
URLconf will look for myapp/.In a request to 07002, the URLconf will
look for myapp/.The URLconf doesn’t look at the request method. In other words, all
request methods – POST, GET, HEAD, etc. – will be routed to the same
function for the same URL.
在您的情况下,将搜索part1 / part2字符串.
标签:django-urls,python,django,regex 来源: https://codeday.me/bug/20191028/1955886.html