TypeError: view must be a callable or a list/tuple in the case of include().
来源:互联网 发布:vb.net和c#区别 编辑:程序博客网 时间:2024/06/07 13:10
转载请注明出处:http://blog.csdn.net/gamer_gyt
博主微博:http://weibo.com/234654758
Github:https://github.com/thinkgamer
背景
最近对自己大学做的一个网站进行了升级简化和美观优化
github地址:https://github.com/Thinkgamer/CyanScikit
然后之前做的时候用的是Python 2.7 + Django 1.8.6,现在这个版本对python和django都进行了升级,使用的是python 3.4+Django 1.10,然后再使用到views的函数的时候便遇到了问题
环境介绍
Django 1.10
Python 3.4
产生问题的场景是:对django的admin后台融合富文本编辑器,用的还是之前django1.8的语法例子,然后就报出了
File "F:\github\CyanScikit\CyanScikit\urls.py", line 22, in <module> url(r"^uploads/(?P<path>.*)$","django.views.static.serve",{"document_root":settings.MEDIA_ROOT,}), File "D:\Program Files\python\lib\site-packages\django\conf\urls\__init__.py", line 85, in url raise TypeError('view must be a callable or a list/tuple in the case of include().')TypeError: view must be a callable or a list/tuple in the case of include().
思考过程
这个问题是写这篇文章的前一天晚上遇到的,但是由于好久没有碰django了,所以一时半会还不知道问题出在哪了,当时一直在想是不是python版本的关系,因为之前遇到过一个问题是,在定义django的models的时候有一个方法
def __unicode__(self): return self.xxx
但这个是在python2.7中的写法,在python3.X中是这样写的
def __str__(self): return self.xxx
所以把误区一直停留在了python版本问题上,导致走路很多弯路也没有解决这个问题
然后上网寻找答案,在这里得到了解决的办法:http://www.imooc.com/qadetail/98920
意思是在django1.10版本中views视图函数的语法出现了变化,需要先导入views视图函数,然后再引用其内部的函数,同时去掉双引号
解决办法
我的使用kindeditor富文本编辑器,使用以下语法出现错误:
from django.conf import settingsfrom CyanScikit.upload import upload_imageurlpatterns = [ url(r'^admin/uploads/(?P<dir_name>[^/]+)$', upload_image, name='upload_image'), url(r"^uploads/(?P<path>.*)$",views.static.serve,{"document_root":settings.MEDIA_ROOT,}), ]
对应的解决办法是修改以上部分为:
from django import viewsfrom CyanScikit.upload import upload_imageurlpatterns = [ url(r'^admin/uploads/(?P<dir_name>[^/]+)$', upload_image, name='upload_image'), url(r"^uploads/(?P<path>.*)$",views.static.serve,{"document_root":settings.MEDIA_ROOT,}),]
OK,解决问题
注意:版本变化之后带来的语法差异
反思
在做项目的时候,思想往往会被固化在以后的某一个时间点,因为我们相信,我们对于该项技术是熟知的,导致我们不再去官网查看文档,然后就会出现一些语法上的错误,同时对于错误的问题分析上要敢于猜想错误出现的原因,并进行迅速的验证和分析,来解决问题,而不是一拖再拖
总而言之,自己还有很多不足的地方需要改善了学习,come on!
最后附两张截图吧,感兴趣的朋友可以 github
- TypeError: view must be a callable or a list/tuple in the case of include()
- TypeError: view must be a callable or a list/tuple in the case of include().
- TypeError: view must be a callable or a list/tuple in the case of include().解决办法
- TypeError: view must be a callable or a list/tuple in the case of include()
- TypeError: view must be a callable or a list/tuple in the case of include()
- django 单元测试报错: view must be a callable or a list/tuple in the case of include().
- django 运行报错view must be a callable or a list/tuple in the case of include()
- django 运行报错view must be a callable or a list/tuple in the case of include()
- python django1.10解决view must be a callable list/tuple in case of include()
- python 学习---isinstance() arg 2 must be a type or tuple of types
- Uncaught (in promise) TypeError: Super expression must either be null or a function
- The type OneInterface cannot be a superinterface of OneInterfaceImpl; a superinterface must be an in
- Caused by: android.view.InflateException: You must specifiy a layout in the include tag: <include la
- Caused by: android.view.InflateException: You must specifiy a layout in the include tag: <include la
- TypeError: dist must be a Distribution instance
- The method onClick(View) of type MainActivity must override or implement a supertype method
- Main application must be in the list of application paths
- Parameter must be a descendant of this view 错误
- Eclipse workspace包含哪些工程的配置文件在什么地方?
- Android复习之旅--ContentProvider
- 如何利用SQL Server With As递归获取层级关系数据
- 机器学习(五):SVM支持向量机_Python
- CodeForces 37d
- TypeError: view must be a callable or a list/tuple in the case of include().
- HDU 1664 Different Digits (数论 -- 鸽笼原理 + BFS搜索 + 余数判重)
- 常见对象_把int数组拼接成字符串的案例改进版
- ubuntu 源码安装java
- FCN 简单梳理
- mybatis 插入递增主键——abc201611090001 abc201611090002
- log信息输出到文件
- MVC框架的简单描述
- S5PV210体系结构