我有一个我希望在带有HttpResponse的现有模板中呈现的模型,我想用json(或html,在这种情况下我不知道如何转换)但是控制台总是在“onerror”ajax功能如下:
<ventas.forms.EmpleadoModelForm object at 0x103649c50> is not JSON serializable
这是视图函数,如果不是POST请求,则以json格式返回渲染表单但不起作用...
def edit_empleado(request, empleado_id):
empleado = get_object_or_404(Empleado, pk=empleado_id)
if request.POST:
form = EmpleadoModelForm(request.POST, instance=empleado)
if form.is_valid():
empleado = form.save()
empleado.save()
return HttpResponseRedirect("/ventas/empleados")
else:
form_errors = form.errors
return render_to_response("ventas/form_empleado.html", {'form_errors':form_errors,'form_empleado':form},
context_instance=RequestContext(request))
else:
form = EmpleadoModelForm(instance=empleado)
return HttpResponse(json.dumps({
"form_empleado": form
}), content_type="application/html")
return render_to_response("ventas/form_empleado.html", {'form_empleado':form},
context_instance=RequestContext(request))
有关如何在json中格式化的任何想法吗?