码迷,mamicode.com
首页 > Web开发 > 详细

Django URLs error: view must be a callable or a list/tuple in the case of include()

时间:2017-11-05 18:35:15      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:ash   ror   code   pretty   href   alter   include   mes   because   

Django 1.10 no longer allows you to specify views as a string (e.g. ‘myapp.views.home‘) in your URL patterns.

The solution is to update your urls.py to include the view callable. This means that you have to import the view in your urls.py. If your URL patterns don‘t have names, then now is a good time to add one, because reversing with the dotted python path no longer works.

  

from django.contrib.auth.views import login
from myapp.views import home, contact

urlpatterns = [
    url(r‘^$‘, home, name=‘home‘),
    url(r‘^contact/$‘, contact, name=‘contact‘),
    url(r‘^login/$‘, login, name=‘login‘),
]

If there are many views, then importing them individually can be inconvenient. An alternative is to import the views module from your app.
 
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views

urlpatterns = [
    url(r‘^$‘, myapp_views.home, name=‘home‘),
    url(r‘^contact/$‘, myapp_views.contact, name=‘contact‘),
    url(r‘^login/$‘, auth_views.login, name=‘login‘),
]

Note that we have used as myapp_views and as auth_views, which allows us to import the views.py from multiple apps without them clashing.

See the Django URL dispatcher docs for more information about urlpatterns.

Django URLs error: view must be a callable or a list/tuple in the case of include()

标签:ash   ror   code   pretty   href   alter   include   mes   because   

原文地址:http://www.cnblogs.com/klsw/p/7788068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!