CZ-NIC / django-forms-encoder

Encode django forms to JSON

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-forms-encoder

Encode django forms to JSON.

Encoded forms follow the structure described in schema.json.

Usage

You can use DjangoFormsEncoder directly with json module from the standard library.

import json
from django_forms_encoder import DjangoFormsEncoder

json.dumps(form, cls=DjangoFormsEncoder)

You can also use filter encode_form in your templates if you add django_forms_encoder to INSTALLED_APPS. This filter will convert the Django form to simple Python structure, that can be easily converted to JSON. You'll probably want to use it together with json_script filter from Django.

{% load django_forms_encoder %}

{{ form|encode_form|json_script:'login-form' }}

About

Encode django forms to JSON

License:GNU General Public License v3.0


Languages

Language:Python 100.0%