FormEncode-Jinja2 is a Jinja2 extension for filling HTML forms via FormEncode.
You can install it from PyPI:
$ pip install FormEncode-Jinja2 # or $ easy_install FormEncode-Jinja2
Simple example in the interactive mode:
>>> import jinja2 >>> import formencode_jinja2 >>> env = jinja2.Environment(extensions=[formencode_jinja2.formfill]) >>> # or if there is already the Jinja environment: >>> env.add_extension(formencode_jinja2.formfill) >>> template = ''' ... {%- formfill {'username': 'robert', 'email': '[email protected]'} ... with {'username': 'This name is invalid'} -%} ... <input type="text" name="username" /> ... <form:error name="username"> ... <input type="password" name="password" /> ... <input type="email" name="email" /> ... </form> ... {%- endformfill -%} ... ''' >>> print env.from_string(template).render() <input type="text" name="username" class="error" value="robert" /> <span class="error-message">This name is invalid</span> <input type="password" name="password" value="" /> <input type="email" name="email" value="[email protected]" /> </form>
on Flask:
from flask import Flask import formencode_jinja2 app = Flask(__name__) app.jinja_env.add_extension(formencode_jinja2.formfill)
Distributed under MIT license.
See also LICENSE
file.
Written by Eunchong Yu.