In which way Flask-WTF simplifies the integration of Flask with WTForms?

796 views Asked by At

I am constructing my first web application based on Flask and I am struggling with selecting an extension to work with forms. I have read in many places that Flask-WTF offers/provides a simple integration with WTForms, but I couldn't found one explanation of this statement.

For me, this question is relevant because using a wrappers (like Flask-WTF) increases the possibility of including packages that in the future could stop being maintained by the creator.

In the end, I would like to know which are the benefits in using Flask-WTF instead of WTForms.

1

There are 1 answers

2
junnytony On BEST ANSWER

Flask-WTF attempts to simplify the interface between Flask and WTForms. It also provides some commonly used widgets/elements such as Recaptcha, File Uploads. Essentially, Flask-WTF helps to abstract and (even enhances) some of the commonly used constructs in WTForms.

For example, using flask_wtf.Form instead of wtf_forms.form.Form allows you to call Form.validate_on_submit() which checks to see if the request was a POST first before calling validate() on the underlying form.

Other examples are the FileRequired and FileAllowed validators for FileField

Although not the ideal scenario, if flask_wtf ever goes away for any reason in the future, it should be straight forward to write a class which mimics its functionality so that you won't have to modify your existing codebase.