django - “urls”函数有时包含在urls.py中 [英] django - "urls" function sometime included in urls.py
问题描述
为什么在某些 urls.py
文件中看到 url(..)
,而在其他的你看到(..)
。
Why is it in some urls.py
files you see url(..)
and in others you see (..)
.
例如
urlpatterns = patterns('',
url('hello','article.view.hello')
)
,其他我看到:
urlpatterns = patterns('',
('article/', include('article.urls'))
)
推荐答案
使用 patterns()
使用 url()
可选。然而,未来,模式
将被弃用,您必须始终使用 url
。请参阅此门票:
The use of patterns()
makes the use of url()
optional. Going forward, however, patterns
will be deprecated and you will have to always use url
. See this ticket:
除了前缀参数之外,
pattern
提供的另一件事是自动将 c> urlpatterns code> URL()。我想删除这个并强制使用url()
将是一个很好的清理。
The other thing that
patterns
provides besides the prefix parameter is automatically wrapping plain tuples inurlpatterns
inurl()
. I think removing this and forcing usage ofurl()
will be a good cleanup.
所以你应该习惯一直使用 url
。
So you should get in the habit of always using url
.
这篇关于django - “urls”函数有时包含在urls.py中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!