Flask-Validates

Form validation with view decorators


License
MIT
Install
pip install Flask-Validates==0.3.0

Documentation

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