Registry / web-framework / flask-wtf

flask-wtf

JSON →
library1.2.2pypypi✓ verified 35d ago

Flask-WTF is a Flask extension (current version 1.2.2) that simplifies form handling by integrating the WTForms library. It provides robust features such as CSRF protection, form validation, file upload support, and reCAPTCHA integration. Maintained by the Pallets organization, it generally sees regular updates, though specific release cadences can vary.

web-frameworkauth-securityserialization
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.553s · 23.6MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 2.3s · import 0.500s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

`Form` was deprecated and removed in favor of `FlaskForm` in versions >= 1.0.0. `FlaskForm` is a Flask-specific subclass of WTForms' `Form` that includes CSRF protection.

from flask_wtf import FlaskForm

Since version 0.9.0, fields (e.g., `StringField`, `PasswordField`) must be imported directly from `wtforms`, not `flask_wtf`.

from wtforms import StringField

Validators are imported directly from `wtforms.validators`.

from wtforms.validators import DataRequired

This quickstart demonstrates a basic Flask application using Flask-WTF to create, render, and validate a simple form. It includes defining a `FlaskForm` subclass, rendering it in an HTML template, and processing its submission with `validate_on_submit()`.

import os from flask import Flask, render_template, request, redirect, url_for from flask_wtf import FlaskForm from wtforms import StringField, SubmitField from wtforms.validators import DataRequired app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'a_very_secret_key_for_dev') class MyForm(FlaskForm): name = StringField('Name', validators=[DataRequired()]) submit = SubmitField('Submit') @app.route('/', methods=['GET', 'POST']) def index(): form = MyForm() if form.validate_on_submit(): name = form.name.data print(f"Form submitted with name: {name}") # In a real app, save 'name' to a database, etc. return redirect(url_for('success', name=name)) return render_template('index.html', form=form) @app.route('/success/<name>') def success(name): return f'Hello, {name}! Your form was submitted successfully.' if __name__ == '__main__': # Example template content (save as templates/index.html) # <form method="POST" action="/"> # {{ form.hidden_tag() }} # <p> # {{ form.name.label }} # {{ form.name(size=30) }} # {% if form.name.errors %} # <ul class="errors"> # {% for error in form.name.errors %} # <li>{{ error }}</li> # {% endfor %} # </ul> # {% endif %} # </p> # <p>{{ form.submit() }}</p> # </form> app.run(debug=True)
Debug
Known footguns
breakingThe base form class `flask_wtf.Form` was deprecated and removed. Applications should now import and inherit from `flask_wtf.FlaskForm`.
breakingWTForms fields (e.g., `StringField`, `IntegerField`) are no longer imported from `flask_wtf`.
gotchaCSRF protection requires `app.config['SECRET_KEY']` to be set to a strong, random string. Without it, Flask-WTF's CSRF features will not work, or forms will fail validation.
gotchaFor forms that include `FileField` for file uploads, the HTML form tag must include `enctype="multipart/form-data"` to ensure file data is correctly sent to the server.
gotchaThe `form.validate_on_submit()` method only validates if the request method is POST, PUT, PATCH, or DELETE. It will always return `False` for GET requests, which can be a common source of confusion.
breakingThe application experienced a timeout during execution. While this is a general execution issue rather than a specific API misuse, it can sometimes be triggered by complex or misconfigured form processing, custom validators, or template rendering involving Flask-WTF. Reviewing related logic for infinite loops or resource-intensive operations is crucial.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
36 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
bytedance
4
claudebot
3
googlebot
3
dotbot
2
Resources