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-4/

User Registration API

Build a Flask API endpoint that handles user registration with profile data and avatar upload. The endpoint should accept both form data and file uploads in a single request.

Requirements

Create a POST endpoint /api/register that:

  1. Accepts user registration data including username, email, password, and bio
  2. Accepts an optional profile avatar image file upload
  3. Validates all required fields are present
  4. Validates the uploaded avatar file (if provided) is an allowed image type (jpg, png, gif)
  5. Returns appropriate success/error responses

The endpoint should handle:

  • Standard form data for text fields
  • File upload for the avatar
  • Proper form validation before processing
  • Appropriate HTTP status codes (200 for success, 400 for validation errors)

Implementation

@generates

API Response Format

Success response (200 OK):

{
  "message": "User registered successfully",
  "username": "john_doe"
}

Validation error response (400 Bad Request):

{
  "error": "Validation failed"
}

Test Cases

  • POST to /api/register with valid form data (username, email, password, bio) and a valid PNG avatar file returns 200 with success message @test
  • POST to /api/register with valid form data but missing required field (e.g., no email) returns 400 with error message @test
  • POST to /api/register with valid form data and an invalid file type (e.g., .txt file) returns 400 with error message @test
  • POST to /api/register with valid form data but no avatar file returns 200 with success message (avatar is optional) @test

Dependencies { .dependencies }

Flask-WTF { .dependency }

Provides form handling and validation for Flask applications, including support for file uploads and CSRF protection.

Version

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