django - “urls”函数有时包含在urls.py中 [英] django - "urls" function sometime included in urls.py

查看:166
本文介绍了django - “urls”函数有时包含在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 in urlpatterns in url(). I think removing this and forcing usage of url() will be a good cleanup.

所以你应该习惯一直使用 url

So you should get in the habit of always using url.

这篇关于django - “urls”函数有时包含在urls.py中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆