Form rendering, validation, and CSRF protection for Flask with WTForms.
72
Build a Flask web form for uploading documents to a content management system. The form should validate uploaded files to ensure only specific document types are accepted.
The upload form must accept the following document types:
Files with other extensions should be rejected with an appropriate error message.
Create a Flask form class with:
The form should provide clear feedback when validation fails.
Implement a Flask application with:
@generates
from flask import Flask, render_template_string, request
from flask_wtf import FlaskForm
app = Flask(__name__)
app.config['SECRET_KEY'] = 'test-secret-key'
class DocumentUploadForm(FlaskForm):
"""Form for uploading documents with extension validation."""
pass
@app.route('/', methods=['GET', 'POST'])
def upload():
"""Handle document upload form display and submission."""
pass
if __name__ == '__main__':
app.run()Provides the web framework for handling routes and requests.
Provides form handling and validation capabilities for Flask applications.
Install with Tessl CLI
npx tessl i tessl/pypi-flask-wtfevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10