django:转换为json [英] django: form to json

查看:100
本文介绍了django:转换为json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将表单序列化为json格式。我的观点:

I am trying to serialize my form into the json format. My view:

form = CSVUploadForm(request.POST, request.FILES)
data_to_json={}
data_to_json = simplejson.dumps(form.__dict__)
return HttpResponse(data_to_json, mimetype='application/json')

我有错误< class'django.forms.util.ErrorList'>不可JSON序列化

推荐答案

您可能想看看名为 django-remote-forms


一个允许您序列化Django表单的程序包,包括字段
和窗口小部件到Python字典中,以便轻松转换为JSON和
通过API公开

A package that allows you to serialize django forms, including fields and widgets into Python dictionary for easy conversion into JSON and expose over API

另请参阅:

  • How to cast Django form to dict where keys are field id in template and values are initial values?

这篇关于django:转换为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆