Painless form validation (WTForms or Flask-WTF) using view decorators.
Using pip:
pip install Flask-Validates
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-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)
python setup.py test
The Sphinx-compiled documentation is available here: http://flask-validates.readthedocs.io/en/latest/
This project is licensed under the MIT License - see the LICENSE file for details