Skip to main content
https://travis-ci.org/Aristotle-Metadata-Enterprises/django-jsonforms.svg?branch=master

django-jsonforms provides a Django integration of json-editor (https://github.com/json-editor/json-editor). A form field is provided that renders the dynamic form created by json-editor, loading in the provided schema and options along with any initial form data. The field can be rendered in the same way as any other django field and also validates submitted data against your json schema on submission.

Installation

Install with pip pip install django-jsonforms

Add django_jsonforms to your INSTALLED_APPS

Make sure you have APP_DIRS set to True in your TEMPLATES setting. More about the templates setting here: https://docs.djangoproject.com/en/2.0/ref/settings/#templates

Requirements

jQuery is required on the page that will be rendering the form.

Usage

The field can be used like any other Django form field, it has the schema and options attributes which can be either python dictionaries or paths to static files as as shown below

  • The schema parameter is the json schema the field will use

  • The options parameter is passed through to the json-editor object, these options are described here: https://github.com/jdorn/json-editor#options (the schema option is not used)

  • An optional ajax parameter determines whether any files are loaded via ajax on the frontend or loaded in the backend and put into html parameters (defaults to true)

Example:

from django.forms import ModelForm, Form
from django_jsonforms.forms import JSONSchemaField

class RegistrySettingsForm(Form):

    json = JSONSchemaField(
        schema = 'schema/schema.json',
        options = 'schema/options.json'
    )

In this example the schema file would be located in ‘static/schema/schema.json’. You will need to run collectstatic after creating the file

To load the file from a directory other than STATIC_ROOT see the JSONFORMS_SCHEMA_DIR setting below

Example showing all options:

class RegistrySettingsForm(Form):

    json = JSONSchemaField(
        schema = 'schema/schema.json',
        options = {"theme": "bootstrap3"},
        ajax = false
    )

Since it is common to have only one field in this type of form. A form with a single JSONSchemaField named json is also available to use

Form Example:

from django_jsonforms.forms import JSONSchemaForm

form = JSONSchemaForm(schema=... , options=... , ajax=...)

Note:

When rendering the form don’t forget to render the forms media with the template tag {{ form.media }}. This is required for the field to function correctly

The data returned when the field is submitted is in the form of a python dictionary. This may need to be converted before being stored depending on the model field being used

Settings

The JSONFORMS_SCHEMA_DIR setting can be used to specify the file directory to load the schema from. This directory will need to be seving static files for the form to funciton correctly

The JSONFORMS_SCHEMA_VALIDATE settings can be set to False to disable backend validation of the submitted json. This can allow a user to submit any json if the frontend validation is bypassed. This settings should only be used during development

Metadata

Release files for django-jsonforms 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-jsonforms 1.1.2
File Size Uploaded
django-jsonforms-1.1.2.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-jsonforms 1.1.2
File Interpreter ABI Platform
django_jsonforms-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / django-jsonforms-1.1.2.tar.gz

Download URL django-jsonforms-1.1.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3854c97345a5cd782b6c30e11b94b64134ababd5f84a825b80a4a585da955cca
BLAKE2b-256 checksum
How to use checksums
f2be0cb73c6952de1996080db930ac1e91443771748d73817ff615bb371be2ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

Release files / django_jsonforms-1.1.2-py3-none-any.whl

Download URL django_jsonforms-1.1.2-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6023b05e9b9dc5bfc3bd63eddd8a3294a7be8a7dfecc2978d316ef8fc64436b4
BLAKE2b-256 checksum
How to use checksums
ae2a7a0ea54a14184a1122f744c5509637c2884eb48a3f0c07b835de663b9adf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page