This question already has an answer here:
这个问题在这里已有答案:
- Django: formats of urlpatterns in urls.py 2 answers
- Django:urls.py中的urlpatterns格式2个答案
Are there benefits for using django.conf.urls.patterns
versus just a list of url?
使用django.conf.urls.patterns与仅列出url有什么好处?
For example what is the difference between
例如,有什么区别
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
vs
VS
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)))
1 个解决方案
#1
7
You should use a list because patterns() is deprecated since version 1.8, and will be removed in 1.10:
您应该使用列表,因为自1.8版以来不推荐使用patterns(),并且将在1.10中删除它:
def patterns(prefix, *args):
warnings.warn(
'django.conf.urls.patterns() is deprecated and will be removed in '
'Django 1.10. Update your urlpatterns to be a list of '
'django.conf.urls.url() instances instead.',
RemovedInDjango110Warning, stacklevel=2
)
#1
7
You should use a list because patterns() is deprecated since version 1.8, and will be removed in 1.10:
您应该使用列表,因为自1.8版以来不推荐使用patterns(),并且将在1.10中删除它:
def patterns(prefix, *args):
warnings.warn(
'django.conf.urls.patterns() is deprecated and will be removed in '
'Django 1.10. Update your urlpatterns to be a list of '
'django.conf.urls.url() instances instead.',
RemovedInDjango110Warning, stacklevel=2
)