我最近将我的Django项目升级到1.9版.
当我尝试运行时migrate
,我收到以下两个错误:
Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.about). Pass the callable instead.
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.
有人可以告诉我如何做到这一点的正确语法?我的简短示例urls.py
如下:
urlpatterns = patterns('', url(r'^about/$', 'app.views.about', name='about'), ) urlpatterns += patterns('accounts.views', url(r'^signin/$', 'auth_login', name='login'), )
谢谢!
直接导入视图或视图模块:
from apps.views import about from accounts import views as account_views
不要使用patterns
,只需使用列表或元组:
urlpatterns = [ url(r'^about/$', about, name='about'), ] urlpatterns += [ url(r'^signin/$', account_views.auth_login, name='login'), ]