Skip to content

Instantly share code, notes, and snippets.

@AphonicChaos
Created March 1, 2016 13:59
Show Gist options
  • Save AphonicChaos/601435a1ec49149b04b8 to your computer and use it in GitHub Desktop.
Save AphonicChaos/601435a1ec49149b04b8 to your computer and use it in GitHub Desktop.
def some_view(request):
form = SomeForm(request.POST)
form_json = {
name: {
"help_text": field.help_text,
"initial": field.initial,
"label": field.label[:],
"max_length": field.max_length,
"min_length": field.min_length,
"required": field.required,
"widget": type(field).__name__,
"widget_attrs": field.widget_attrs(field.widget),
} for name, field in form.fields.items() }
return HttpResponse(json.dumps(form_json, content_type="application/json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment