<ImageFieldFile:XXXX> is not JSON serializable
问题描述:
使用django.forms.model下的model_to_dict来序列化ImageFieldFile出现不能序列化错误
使用json.dumps会出现同样的情况
解决办法:
方法一:
# 为ImageFieldFile类型手动转为字符串类型
img = str(instance.imagefield)
方式二:
# 使用django.core.serializers下的serialize方法
json_data = serialize('json', model_obj)

<ImageFieldFile:XXXX> is not JSON serializable的更多相关文章
- python datetime.datetime is not JSON serializable
1.主要是python list转换成json时对时间报错:datetime.datetime(2014, 5, 23, 9, 33, 3) is not JSON serializable. 2. ...
- datetime is not json serializable
python, datetime is not json serializable import datetime def json_serial(obj): """JS ...
- celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式
#python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...
- Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化
Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
- TypeError: Object of type 'int32' is not JSON serializable ——已解决
将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...
- [Python] json 报错'xxx is not JSON serializable'的处理方法
predictions = self.model.predict(x_data, verbose=0)[0] y_pred_idx = np.argmax(predictions) y_pred_pr ...
- [Python]json 错误xx is not JSON serializable
TypeError: Decimal('1457501') is not JSON serializable 在使用json的时候经常会遇到xxx is not JSON serializable, ...
- python:datetime.datetime is not JSON serializable 报错问题解决
问题: 项目使用django开发,返回的数据中有时间字段,当json.dumps()时提示:datetime.datetime is not JSON serializable 解决: import ...
随机推荐
- Java调用WebService方法总结(5)--Axis2调用WebService
Axis2是新一点Axis,基于新的体系结构进行了全新编写,有更强的灵活性并可扩展到新的体系结构.文中demo所使用到的软件版本:Java 1.8.0_191.Axis2 1.7.9. 1.准备 参考 ...
- GIt三剑客
一. Github 什么是Github? github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开. Github 由Chris Wan ...
- 【雅思】【绿宝书错词本】List13~24
List 13 ❤audacious a.大胆的:有冒险精神的:鲁莽的:厚颜无耻的 ❤tramp v.跋涉:踩踏 n.长途跋涉 ❤lexicographer n.词典编纂者 ❤manipulate v ...
- 使用企业证书给iOS应用重签
来源:https://github.com/sailtsao/iReSign 这里有个开源的签名工具,已经修改为支持dylib frameworks等的签名了,使用这个签名不会出现任何问题 iReSi ...
- 微信小程序实现下拉刷新上拉加载
代码片段:https://developers.weixin.qq.com/s/K9VbWZmy7e8C
- iOS应用状态保存和恢复
当应用被后台Kill掉的时候希望从后台返回的时候显示进入后台之前的内容 在Appdelegate中设置 - (BOOL)application:(UIApplication *)application ...
- 跨服务器查询sql语句样例(转)
若2个数据库在同一台机器上: insert into DataBase_A..Table1(col1,col2,col3----) select col11,col22,col33-- from Da ...
- 在SQL查询结果中添加自增列的两种方法
解决办法<一>:如果想查询出这个表的信息,并添加一列连续自增的ID,可用如下查询语句: SELECT Row_Number() over ( order by getdate() ) as ...
- WebSocketServer
@Component @ServerEndpoint(value = "/endpoint/ws") public class WebSocketServer { private ...
- 微信小程序~获取位置信息
微信小程序提供的getlocation来获取用户的定位,能够得到用户的经纬度信息 (注:getloaction需要用户授权scope.userLocation)结合map组件能够得到用户的详细定位 & ...