django-dict-form
Lightweight Django Forms extension. Adds as_dict() — serializes form definitions to Python dicts / JSON, making forms easier to integrate with REST APIs, SPA frontends (React/Vue), dynamic UI generators, and low-code systems.
Extends standard Django form rendering (as_p, as_table, as_ul) with machine-readable field metadata, validation rules, and widget configuration.
When is this convenient?
Write adapters to UI/UX components once — forms auto-generate on frontend. Backend edits propagate automatically. No manual frontend form duplication.
Features
- Serialize Django forms to Python dictionaries
- Useful for dynamic frontend rendering
- Simplifies API-driven form generation
- Lightweight and framework-friendly
- Compatible with standard Django Forms
Install
pip install django-dict-form
Quick Start
from django_dict_form.form import DictForm
from django import forms
class ContactForm(DictForm):
name = forms.CharField(max_length=100)
email = forms.EmailField()
message = forms.CharField(widget=forms.Textarea)
form = ContactForm()
data = form.as_dict()
Output:
{
"name": {
"label": null,
"required": true,
"disabled": false,
"help_text": "",
"initial": null,
"show_hidden_initial": false,
"label_suffix": null,
"widget": {
"name": "TextInput",
"type": "text",
"is_hidden": false,
"required": true,
"choices": [],
"attrs": {"maxlength": "100"}
}
}
}
Mixin Usage
Use RenderableDictFormMixin to add as_dict() to any existing form class:
from django_dict_form.form import RenderableDictFormMixin
from django import forms
class MyForm(forms.Form, RenderableDictFormMixin):
field = forms.CharField()
as_dict() Output Schema
Each field produces:
| Key | Type | Description |
|---|---|---|
label |
str | null |
Field label |
label_suffix |
str | null |
Label suffix |
required |
bool |
Whether field is required |
disabled |
bool |
Whether field is disabled |
help_text |
str |
Help text |
initial |
any |
Default value |
show_hidden_initial |
bool |
Show hidden initial widget |
widget |
dict |
Widget metadata (see below) |
Widget dict:
| Key | Type | Description |
|---|---|---|
name |
str |
Widget class name (e.g. TextInput) |
type |
str | null |
HTML input type (e.g. text, email, number) |
is_hidden |
bool |
Whether widget is hidden |
required |
bool |
Widget-level required |
choices |
list[{value, name}] |
Options for select widgets |
attrs |
dict |
HTML attributes (e.g. maxlength, min, max) |
Supported Fields
| Field | Widget | Notes |
|---|---|---|
CharField |
TextInput |
maxlength, minlength in attrs |
IntegerField |
NumberInput |
min, max in attrs |
FloatField |
NumberInput |
step: any in attrs |
EmailField |
EmailInput |
maxlength: 320 default |
URLField |
URLInput |
|
BooleanField |
CheckboxInput |
|
ChoiceField |
Select |
choices serialized |
DateField |
DateInput |
|
TimeField |
TimeInput |
|
DateTimeField |
DateTimeInput |
|
DurationField |
TextInput |
|
RegexField |
TextInput |
|
UUIDField |
TextInput |
Custom widgets supported — pass any widget instance, choices and attrs extracted automatically.
Requirements
- Python >= 3.11.15
- Django >= 3.2
License
MIT — Gleb Uvarov
Release files for django-dict-form 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_dict_form-0.11.0.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_dict_form-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / django_dict_form-0.11.0.tar.gz
| Download URL | django_dict_form-0.11.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f8b3de6302b53217e88d6f40ebb47431b883007771c724933ea3cb587e8422a
|
|
BLAKE2b-256 checksum How to use checksums |
002caf0cec55e7e9f3c83ba57ada00c1e5e999067cef1cb28cac91041ccef8fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|
Release files / django_dict_form-0.11.0-py3-none-any.whl
| Download URL | django_dict_form-0.11.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38b5b9882923066579ca5f8ab64c593ba57337f14f489457cc679e7a7061f9ce
|
|
BLAKE2b-256 checksum How to use checksums |
2d81b3a6d67040e0679853db9db4ca76ccc517d94837b4755ba093167247a553
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|