简体   繁体   English

django中的url模式正则表达式

[英]Url pattern regex in django

This is aa basic question but I'm having trouble finding the answer in in docs: 这是一个基本问题,但我在文档中找不到答案:

Lets say I have a url like: 可以说我有一个网址:

http://example.com/part1/part2

and I have: 我有:

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'xxx', name='yyy'),

)

What part of the url string above is attempted to be matched by the regex between ^ and $ ? 上面的url字符串的哪一部分试图与^$之间的正则表达式匹配?

I've read through numerous sources and docs including: 我读过很多来源和文档,包括:

This is stated in the documentation clearly: 这在文档中明确说明:

The URLconf searches against the requested URL, as a normal Python string. URLconf将搜索请求的URL,作为普通的Python字符串。 This does not include GET or POST parameters, or the domain name. 这不包括GET或POST参数或域名。

For example, in a request to http://www.example.com/myapp/ , the URLconf will look for myapp/. 例如,在对http://www.example.com/myapp/的请求中,URLconf将查找myapp /。

In a request to http://www.example.com/myapp/?page=3 , the URLconf will look for myapp/. http://www.example.com/myapp/?page=3的请求中,URLconf将查找myapp /。

The URLconf doesn't look at the request method. URLconf不查看请求方法。 In other words, all request methods – POST, GET, HEAD, etc. – will be routed to the same function for the same URL. 换句话说,所有请求方法 - POST,GET,HEAD等 - 将被路由到同一URL的相同功能。

In your case, part1/part2 string would be searched against. 在您的情况下,将搜索part1/part2字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM