Sometimes form.as_p doesn't cut it. This app adds more render methods to all forms.
Project description
Django Form Renderers
Sometimes form.as_p doesn’t cut it. This app adds more render methods to all forms.
Installation
Install or add django-form-renderers to your Python path.
Add form_renderers to your INSTALLED_APPS setting.
What it does
Every form receives a div-based render method called as_div.
If a field is required then an attribute required="required" is rendered for every widget. This is a safe blanket assumption.
Optional - every field and input gets extra BEM CSS classes.
Defining your own renderers
Create either form_renderers.py or form_renderers/__init__.py in your app. Each renderer must be a function:
def as_some_renderer(form): return form._html_output( ... ) def as_another_renderer(form): return form._html_output( ... )
You can override the default as_div by creating a renderer called as_div in your app. The same rules that apply for Django template overriding apply to renderer overriding.
BEM
BEM is a CSS naming convention that advocates explicit naming over inheritance. Django forms, fields and widgets are not BEM aware. To enabled BEM classes from settings do:
FORM_RENDERERS = {"enable-bem-classes": True}
Changelog
0.2
Optional BEM classes.
Standardize as_div.
0.1.1
Allow apps to specify custom renderers.
0.1
First release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-form-renderers-0.2.tar.gz
.
File metadata
- Download URL: django-form-renderers-0.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 845424555c567593c895edeed92b2f2a3269d687552261efcb63906d9bdaf1bb |
|
MD5 | 606720cc65e959636d75c8b8ac7c5490 |
|
BLAKE2b-256 | 447f341e7b374350f0db1964df482cfacabd9f2aa1bb6141f4e1b18e3025a8bd |
Provenance
File details
Details for the file django_form_renderers-0.2-py2.7.egg
.
File metadata
- Download URL: django_form_renderers-0.2-py2.7.egg
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 250f01142a73ee6187f85e6932bf14edb9b99c275ae0459ea2f1200c2edc2221 |
|
MD5 | 3fcc6acff0f8668023d62773d0a8f39c |
|
BLAKE2b-256 | ced82d7cf9da91139824947b9c5a8183b9702426e7ce2e1e102a3c35bfc947e7 |