问题描述:

  使用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. 【SP1811】 LCS - Longest Common Substring(后缀自动机)

    题目链接 对第一个串建出\(SAM\),然后用第二个串去匹配. 如果能往下走就往下走,不能的话就跳parent tree的父亲,直到能走为止.如果跳到\(0\)了还是不能走,重新匹配. #includ ...

  2. elasticsearch授权访问

    1.search guard插件 https://www.cnblogs.com/shifu204/p/6376683.html 2.Elasticsearch-http-basic 不支持es5,忽 ...

  3. Keepalived简单理解

    Keepalived Keepalived是一个基于VRRP协议来实现的LVS服务高可用方案,可以利用其来避免单点故障.一个LVS服务会有2台服务器运行Keepalived,一台为主服务器(MASTE ...

  4. python day 9: xlm模块,configparser模块,shutil模块,subprocess模块,logging模块,迭代器与生成器,反射

    目录 python day 9 1. xml模块 1.1 初识xml 1.2 遍历xml文档的指定节点 1.3 通过python手工创建xml文档 1.4 创建节点的两种方式 1.5 总结 2. co ...

  5. Angular应用架构设计-3:Ngrx Store

    这是有关Angular应用架构设计系列文章中的一篇,在这个系列当中,我会结合这近两年中对Angular.Ionic.甚至Vuejs等框架的使用经验,总结在应用设计和开发过程中遇到的问题.和总结的经验, ...

  6. 使用layui框架根据字段来设置tr行的背景色

    问题来源:最近在写公司项目时使用layui遇见的问题,老板要求根据td字段来设置整行tr的背景色. 解决:一开始数据比较少的时候只是直接在页面根据js动态判断字段然后来更改背景色,结果能够成功,但是后 ...

  7. 二进制安装docker-18.06.3-ce

    二进制安装docker 1,下载 https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz 2,解压, ...

  8. 解决ifuse不支持24位UDID问题

    在使用ifuse对iphone设备进行沙盒挂载时, 对类似XXXXXXXX-XXXXXXXXXXXXXXXX UDID设备会提示Invalid device UDID specified, lengt ...

  9. kubernetes-使用Nginx配置ingress-controllers

    下载 Nginx Ingress Controller 配置文件: wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/ma ...

  10. 【转】高性能网络编程3----TCP消息的接收

    这篇文章将试图说明应用程序如何接收网络上发送过来的TCP消息流,由于篇幅所限,暂时忽略ACK报文的回复和接收窗口的滑动. 为了快速掌握本文所要表达的思想,我们可以带着以下问题阅读: 1.应用程序调用r ...