Django文档显示了这样的例子:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^articles/2003/$', views.special_case_2003),
]
但是,我看到一些看起来像这样的代码:
from django.conf.urls import url
urlpatterns = [
url(r'^articles/2003/$', 'myapp.views.special_case_2003'),
]
其中special_case_2003
是myapp/views.py
中函数的名称。
这两种方法有什么区别?
答案 0 :(得分:2)
urlpatterns = [
url(r'^articles/2003/$', 'myapp.views.special_case_2003'),
]
这样的代码已经过时了。将视图提供为字符串is deprecated in Django 1.8和does not work in Django 1.10+。在Django 1.10+中,您必须使用callable。