Skip to main content

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.

Travis

Installation

  1. Install or add django-form-renderers to your Python path.

  2. Add form_renderers to your INSTALLED_APPS setting.

What it does

  1. Every form receives a div-based render method called as_div.

  2. If a field is required then an attribute required="required" is rendered for every widget. This is a safe blanket assumption.

  3. 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}

Authors

Praekelt Consulting

  • Hedley Roos

Changelog

0.3.1

  1. Add a setting allowing as_p and as_table to be overridden globally.

0.3

  1. Add a span tag hook for choice inputs. This allows CSS selectors to target the text inside the label tag.

0.2

  1. Optional BEM classes.

  2. Standardize as_div.

0.1.1

  1. Allow apps to specify custom renderers.

0.1

  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

django-form-renderers-0.3.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_form_renderers-0.3.1-py2.7.egg (13.9 kB view details)

Uploaded Egg

File details

Details for the file django-form-renderers-0.3.1.tar.gz.

File metadata

File hashes

Hashes for django-form-renderers-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7ab7cc0422bbb2a23558b421b3506c44cb74f60959ffdda1dfcff8e44aab2b2c
MD5 88fa04a92d799387288d0944f068dab4
BLAKE2b-256 1f3a5b9352ed7df4dcb44f0c2fa07aa6b7d47ac30c7b87907a22e0da5531cc8b

See more details on using hashes here.

File details

Details for the file django_form_renderers-0.3.1-py2.7.egg.

File metadata

File hashes

Hashes for django_form_renderers-0.3.1-py2.7.egg
Algorithm Hash digest
SHA256 1c69d4f663c2d676dd98944bf24be4ac6f7ee484832b0e603c239b990f15f665
MD5 72f9558408a721fd485a8e5f5124b38d
BLAKE2b-256 736990976508071beab1b288f3eedc96140b4a47a6bd03be01c5a47ae5083230

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page