django static Cannot mix str and non-str arguments
来源:互联网 发布:淘宝上的图片怎么保存 编辑:程序博客网 时间:2024/05/17 09:27
I don't know what the difference is supposed to be, but I found a use case difference (using django 1.9.1 running via apache, wsgi on Python 3.4). In my app, I have some images in ImageFields
in the database. If I use code like this in my template:
<a href="object-{{object.id}}"><img src="{% static object.image %}" height="200px"></a>
then, if I use {% load static %}
, django thorws a TypeError
(Cannot mix str and non-str arguments
). This is presumably because the object.image
is not a string, it's an ImageField
, that gets converted to a string at some later stage. However, if one uses {% load staticfiles %}
no such error occurs.
Unfortunately, I discovered this difference after spending hours trying to debug the problem. I managed to find a workaround for when using the first option, namely to add a string-converter method to the object like this:
#image stringdef image_str(self): return str(self.image)
Hope this knowledge will be of use to someone.
原链接:https://stackoverflow.com/questions/24238496/what-is-the-difference-between-load-staticfiles-and-load-static
- django static Cannot mix str and non-str arguments
- str[] , *str , static str[]的区别
- str
- str()
- str
- str
- str
- wstr and str
- str and repr 函数
- static int LinesCount(string str)
- ISE错误:“Cannot mix blocking and non blocking assignments on signal ”
- ISE错误:“Cannot mix blocking and non blocking assignments on signal ”
- Python字符串与数字拼接 TypeError: cannot concatenate 'str' and 'int' objects
- Django错误'str' object is not callable
- static std::string jstring2string (jstring str)
- ISE verilog 综合错误提示:ERROR:Xst:880 - "Johnson_source.v" line 45: Cannot mix blocking and non blocking
- str=str.replace("<","!");
- str.compareTo(str)
- Linux的SOCKET编程 简单演示
- 使用particles.js实现知乎首页Canvas粒子效果,多边形,圆形粒子
- 踽踽独行
- Struts2--ogln详解
- PDO 创建PDO对象与链接相关设置
- django static Cannot mix str and non-str arguments
- c++基础(4)
- 使用 @RequestMapping 处理动态 URI
- 使用Google Search Console中的搜索查询数据的方法
- SpringMVC 使用@ResponseBody返回json 中文乱码
- 总结Java垃圾回收器的方法和原理
- Android的build文件findleaves.py分析
- iOS 获取设备唯一标示符的方法
- 解决VMware虚拟机网络时长中断的问题