本文介绍了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')
我有错误
.如何处理 django 表单?
I have the error <class 'django.forms.util.ErrorList'> is not JSON serializable
. What to do to handle django forms?
推荐答案
您可能需要查看名为 django-remote-forms:
You may want to look at the package called 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
另见:
如何将 Django 表单转换为 dict,其中键是模板中的字段 id,值是初始值?这篇关于django:表单到 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论