问题描述:

  使用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的更多相关文章

  1. python datetime.datetime is not JSON serializable

    1.主要是python  list转换成json时对时间报错:datetime.datetime(2014, 5, 23, 9, 33, 3) is not JSON serializable. 2. ...

  2. datetime is not json serializable

    python, datetime is not json serializable import datetime def json_serial(obj): """JS ...

  3. 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 ...

  4. Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化

    Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...

  5. TypeError: Object of type 'int64' is not JSON serializable

    错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...

  6. TypeError: Object of type 'int32' is not JSON serializable ——已解决

    将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...

  7. [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 ...

  8. [Python]json 错误xx is not JSON serializable

    TypeError: Decimal('1457501') is not JSON serializable 在使用json的时候经常会遇到xxx  is not JSON serializable, ...

  9. python:datetime.datetime is not JSON serializable 报错问题解决

    问题: 项目使用django开发,返回的数据中有时间字段,当json.dumps()时提示:datetime.datetime is not JSON serializable 解决: import ...

随机推荐

  1. 2019年北航OO第三次博客总结

    一.JML语言理论基础及其工具链 1. JML语言理论基础 JML是用于对Java程序进行规格化设计的一种表示语言,是一种行为接口规格语言(Behavior Interface Specificati ...

  2. ColdFusion 编写WebService 示例

    1.开发 Web Services,编写cfcdemo.cfc组件,代码如下: <cfcomponent style ="document" namespace = &quo ...

  3. JS中的函数与对象

    创建函数的三种方式 1.函数声明 function calSum1(num1, num2) { return num1 + num2; } console.log(calSum1(10, 10)); ...

  4. TypeScript_基础数据类型

    TypeScript 的基础数据类型包含: string.number.boolean.array .object.null.undefined.enmu.void.never.any.tuple 注 ...

  5. 【大数据技术能力提升_2】numpy学习

    numpy学习 标签(空格分隔): numpy python 数据类型 5种类型:布尔值(bool),整数(int),无符号整数(uint).浮点(float).复数(complex) 支持的原始类型 ...

  6. MySQL关闭缓慢

    Pre环境有个MySQL不能进行数据写入操作,关闭实例也非常慢,最后error报错. 最后发现是磁盘不能进行写操作. touch /data/testtouch: cannot touch ‘/dat ...

  7. c# 格式化数据String.Format

  8. The Essential Burp Suite

    OK   we have download teh burp suite .let's begin start the tool 1.if  we  want to use the total mem ...

  9. mysql Starting MySQL..The server quit without updating PID file

    可能的原因和解决办法 1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限解决方法 :给予权限,执行 chown -R mysql:mysql /var/data ...

  10. IDRAC 固件升级操:

    Internal Use - Confidential IDRAC 固件升级操作: R630:https://downloads.dell.com/FOLDER05590166M/1/iDRAC-wi ...