{ "info": { "author": "Benjamin Mampaey", "author_email": "bmampaey@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.0", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# django-boundfield-renderer\nA rendering engine for Django forms using templatetags\n\n## Preamble\nThere are already many libraries to render Django forms in templates, including the default Form methods as_p(), as_ul(), as_table(). Unfortunately, none of them (that I have encountered at least) apply strictly the concept of separation of form and function, or business logic from presentation, etc. Django has made a step into the right direction by using templates for the widgets, but the entirety of a field rendering is still partially done in python code. For example, if the developer wishes to put the label after the checkbox, he still has to write python, instead of redefining a template.\n\nThis library defines one or more registry, that associate a rendering function (called renderer) for each form field class. That rendering function is made available through the templatetag `renderer`.\n\n## Installation\nAdd `'boundfield_renderer'` to your INSTALLED_APPS setting so Django can find the templatetag `renderer`.\n\n## Basic steps to render a Django Form\n### Create a registry and register the renderers for the field classes\nFor example, in the file *path/to/my_registry.py*\n```python\nfrom django import forms\nfrom django.template.loader import get_template\nfrom boundfield_renderer import RendererRegistry\n\n# Create the registry\nregistry = RendererRegistry()\n\n# Define a renderer function for a field class, for example the CharField\n# This can be as simple as the render method of a template\ntemplate_render = get_template('mytemplates/char_field.html').render\n\n# Register the renderer for the field class in the registry\n# Either by setting it directly on the registry\nregistry[forms.CharField] = template_render\n\n# Or by using the register method as a decorator on a field class definition\n@registry.register(get_template('mytemplates/my_field.html').render)\nclass MyField(forms.Field):\n\tpass\n\n```\n\nThe file *mytemplates/char_field.html* could be as simple as this:\n```html\n\n
{{ help_text }}
\n