Python Forms Library with Jinja2 Templates based on Valley
- 2.7
- 3.3
- 3.4
- 3.5
pip install formy
Form definition
from formy import *
class PersonForm(Form):
first_name = CharField(required=True)
last_name = CharField(required=True)
email = EmailField()
slug = SlugField(required=True,help_text='ex. duke-university')
Template based on a generic HTML unordered list (ul) element. This is the default template.
from formy import *
class PersonForm(Form):
_template = 'formy.templates.form.ul_template'
first_name = CharField(required=True)
last_name = CharField(required=True)
email = EmailField()
slug = SlugField(required=True,help_text='ex. duke-university')
Template based on a generic HTML table element.
from formy import *
class PersonForm(Form):
_template = 'formy.templates.form.table_template'
first_name = CharField(required=True)
last_name = CharField(required=True)
email = EmailField()
slug = SlugField(required=True,help_text='ex. duke-university')
Template based on the Bootstrap CSS framework. Requires that you have the Bootstrap CSS loaded on your HTML page.
from formy import *
class PersonForm(Form):
_template = 'formy.templates.form.bootstrap_template'
first_name = CharField(required=True)
last_name = CharField(required=True)
email = EmailField()
slug = SlugField(required=True,help_text='ex. duke-university')
>>form = PersonForm()
>>form.render(include_submit=True)
u' <ul class="ul form">
<li><label for="id_first_name">First Name</label> <input type="text" name="first_name" placeholder="First"/>
</li>
<li><label for="id_last_name">Last Name</label> <input type="text" name="last_name" placeholder="Last"/></li>
<li><label for="id_email">Email</label> <input type="email" name="email" placeholder="Email"/></li>
<li><label for="id_slug">Slug</label> <input type="text" name="slug" placeholder="Slug"/> <span>ex. duke-university</span>
</li>
<li><input type="submit" value="submit"/></li>
</ul>'
>>form.is_valid
False
>>form_kwargs = {'first_name':'Curious','last_name':'George','email':'[email protected]','slug':'curious-george'}
>>form = PersonForm(**form_kwargs)
>>form.render(include_submit=True)
u'<ul class="ul form">
<li><label for="id_first_name">First Name</label> <input type="text" name="first_name" value="Curious"
placeholder="First"/></li>
<li><label for="id_last_name">Last Name</label> <input type="text" name="last_name" value="George"
placeholder="Last"/></li>
<li><label for="id_email">Email</label> <input type="email" name="email" value="[email protected]"
placeholder="Email"/></li>
<li><label for="id_slug">Slug</label> <input type="text" name="slug" value="curious-george" placeholder="Slug"/>
<span>ex. duke-university</span></li>
<li><input type="submit" value="submit"/></li>
</ul>'
>>form.is_valid
False
>>form.validate()
>>form.is_valid
True
Twitter::@brianjinwright Github: bjinwright