分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

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

发布时间:2023-09-06 01:23责任编辑:郭大石关键词:暂无标签

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 loginfrom myapp.views import home, contacturlpatterns = [ ???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_viewsfrom myapp import views as myapp_viewsurlpatterns = [ ???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()

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved