A Jinja2 extension for filling forms via FormEncode
Project description
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
Usage
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': 'robert153@usrobots.com'} ... 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="robert153@usrobots.com" /> </form>
on Flask:
from flask import Flask import formencode_jinja2 app = Flask(__name__) app.jinja_env.add_extension(formencode_jinja2.formfill)
License
Distributed under MIT license. See also LICENSE file.
Written by Eunchong Yu.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.