Skip to content
/ formy Public

Python Forms Library with Jinja2 Templates. Based on Valley

License

Notifications You must be signed in to change notification settings

capless/formy

Repository files navigation

Formy

Python Forms Library with Jinja2 Templates based on Valley

Unittests

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

About

Python Forms Library with Jinja2 Templates. Based on Valley

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published