Sometimes form.as_p doesn't cut it. This app adds more render methods to all forms. It also adds BEM style CSS classes to all form widgets and inputs.
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.
Replace as_p and / or as_table globally
Most third party apps use as_p or as_table for rendering. Replace it globally by setting:
FORM_RENDERERS = {"replace-as-p": True, "replace-as-table": True}
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.3.2
Django 1.10 tests pass. Handle Django 1.11 widget refactor gracefully.
0.3.1
Add a setting allowing as_p and as_table to be overridden globally.
0.3
Add a span tag hook for choice inputs. This allows CSS selectors to target the text inside the label tag.
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.3.2.tar.gz
.
File metadata
- Download URL: django-form-renderers-0.3.2.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69bd378ce5dd58a01b7e6f2473a5a1b2e23fc9bf05117aed3a695a965439ab10 |
|
MD5 | ac90286c6325dcab31bf2dad00aa9486 |
|
BLAKE2b-256 | 85fd02f09f7ebd7aed6971e82c98afdc69339e9ab7c11e7692f69d9c7d606a6e |
File details
Details for the file django_form_renderers-0.3.2-py2.7.egg
.
File metadata
- Download URL: django_form_renderers-0.3.2-py2.7.egg
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a20f93aa0010d50963b862afb1bde1e4cdc57765104c09867a94d2f06828ef17 |
|
MD5 | edab5ee52abd51eaecb0d63227846c5a |
|
BLAKE2b-256 | c17a723e81e184cf9df19645bce7552322f013c095ad3e72ea2d3f9a03f90e2c |