Skip to content

tjpnz/flask-validates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Validates

Build Status Documentation Status

Painless form validation (WTForms or Flask-WTF) using view decorators.

Installation

Using pip:

pip install Flask-Validates

Usage

Most interaction with Flask-Validates is through validates for decorating views and current_form for getting a reference to the form bound to the given route. The following example demonstrates a simple use of the validates decorator which validates a form with two fields:

@app.route("/", methods=["GET", "POST"])
@validates(
    email=StringField(validators=[DataRequired(), Email()]),
    comments=TextAreaField(validators=[DataRequired()])
)
def index():
    if request.method == "POST" and current_form.validate():
        flash("Your feedback has been submitted")
        return redirect(url_for("index"))
    return render_template("contact_form.html.j2", form=current_form)

See examples for more comprehensive examples of usage.

Flask-WTF Support

Flask-Validates can be used with Flask-WTF (and should be compatible with any other WTForms based integration) by initializing the Flask-Validates extension with the FlaskForm class:

FlaskValidates(app, FlaskForm)

Running the tests

python setup.py test

Documentation

The Sphinx-compiled documentation is available here: http://flask-validates.readthedocs.io/en/latest/

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Painless form validation using view decorators.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages