CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-flask-wtf

tessl install tessl/pypi-flask-wtf@1.2.0

Form rendering, validation, and CSRF protection for Flask with WTForms.

Agent Success

Agent success rate when using this tile

72%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.91x

Baseline

Agent success rate without this tile

79%

task.mdevals/scenario-10/

Document Upload Form

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.

Requirements

Form Validation

The upload form must accept the following document types:

  • PDF documents (.pdf)
  • Microsoft Word documents (.doc, .docx)
  • Text files (.txt)

Files with other extensions should be rejected with an appropriate error message.

Form Structure

Create a Flask form class with:

  • A file upload field that accepts a single document
  • A submit button

The form should provide clear feedback when validation fails.

Web Application

Implement a Flask application with:

  • A route that displays the upload form (GET request)
  • A route that processes form submissions (POST request)
  • When validation succeeds, display the uploaded filename
  • When validation fails, re-display the form with error messages

Test Cases

  • Uploading a PDF file with extension .pdf succeeds @test
  • Uploading a Word document with extension .docx succeeds @test
  • Uploading a text file with extension .txt succeeds @test
  • Uploading an image file with extension .jpg fails with validation error @test
  • Uploading a file with extension .PDF (uppercase) succeeds @test

Implementation

@generates

API

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()

Dependencies { .dependencies }

Flask { .dependency }

Provides the web framework for handling routes and requests.

Flask-WTF { .dependency }

Provides form handling and validation capabilities for Flask applications.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/flask-wtf@1.2.x
tile.json