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.

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. 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.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

django_form_renderers-0.3-py2.7.egg (13.6 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-form-renderers-0.3.tar.gz
Algorithm Hash digest
SHA256 e7877f1dd607c8e978fe0ee40190398c9343c4eda833d339cd22115f8559d589
MD5 37de12d9cd77ab11f66f319688f59e9e
BLAKE2b-256 fa80dffaac88cf7040ab7a89e097f0a7a19c0a96f7ceb58759b2b7cde0ad708d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for django_form_renderers-0.3-py2.7.egg
Algorithm Hash digest
SHA256 be4054ffad5f4c298808f91640f2a7b3b7d89603bf199a563c0a0f6e057ef63b
MD5 aad5dfc5d7eacc9170682a2cd4cf49b3
BLAKE2b-256 7b009267daeea9e9d9758590290015b456ec8cffb8e89b97ed712988ef123b15

See more details on using hashes here.

Provenance

Supported by

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