CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-flask-wtf

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

72

0.91x
Overview
Eval results
Files

task.mdevals/scenario-3/

Document Upload Form

Build a Flask web application with a document upload form that validates file types using predefined upload sets. The application should support two types of documents: images and text documents, with different allowed extensions for each category.

Requirements

Create a Flask application with the following features:

  1. Upload Configuration: Define two upload categories:

    • Images: Allow files with extensions jpg, png, gif
    • Documents: Allow files with extensions txt, pdf, doc, docx
  2. Upload Form: Create a web form with:

    • An "image" file upload field that only accepts image files
    • A "document" file upload field that only accepts document files
    • A submit button
  3. Validation: The form should validate uploaded files using the upload set configurations. Invalid file types should trigger appropriate validation errors.

  4. Routes: Implement two routes:

    • GET /upload: Display the upload form
    • POST /upload: Handle form submission and validation
  5. Success Response: When files are successfully validated, return a simple success message showing which files were uploaded (e.g., "Uploaded: photo.jpg and report.pdf").

Test Cases

  • The form rejects an image upload field with a .txt file @test
  • The form rejects a document upload field with a .jpg file @test
  • The form accepts valid image files (jpg, png, gif) in the image field @test
  • The form accepts valid document files (txt, pdf, doc, docx) in the document field @test

Implementation

@generates

Dependencies { .dependencies }

Flask { .dependency }

Provides the web framework for building the application.

Flask-WTF { .dependency }

Provides form handling, validation, and file upload support.

Flask-Uploads { .dependency }

Provides upload set configuration for organizing file uploads by type.

Install with Tessl CLI

npx tessl i tessl/pypi-flask-wtf

tile.json