Python Forms Library with Jinja2 Templates. Based on Valley
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
formy
.bumpversion.cfg bumped version number, added notes to the HISTORY.md Apr 15, 2017
.gitignore
.travis.yml
HISTORY.md
LICENSE Initial commit Mar 13, 2017
README.md Added link to Valley Apr 5, 2017
requirements.txt
setup.py

README.md

Formy

Python Forms Library with Jinja2 Templates based on Valley

Build Status

Python Versions Supported

  • 2.7
  • 3.3
  • 3.4
  • 3.5

Getting Started

Install

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 Choices

UL Template

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')
    
Table Template

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')
    
Bootstrap Template

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 blank instance

>>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 instance with kwargs

>>form_kwargs = {'first_name':'Curious','last_name':'George','email':'curious@george.com','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="curious@george.com"
                                                       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

Author

Twitter::@brianjinwright Github: bjinwright