我正在使用一些较旧的 Django 代码,并且该url
函数未在任何地方使用,类似于Django 1.4 文档中的示例:
from django.conf.urls import patterns, url, include
urlpatterns = patterns('',
(r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
但我在Django 1.5 文档中注意到该url
函数经常使用:
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^articles/2003/$', 'news.views.special_case_2003'),
url(r'^articles/(\d{4})/$', 'news.views.year_archive'),
url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
为什么是这样?这是惯例问题,还是有使用该url
功能的技术原因?将来我应该遵循哪种做法,我应该如何在没有url
调用的情况下维护我的遗留代码?