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

Form Configuration API

A Flask application that provides an endpoint for dynamically creating forms with configurable CSRF protection.

Requirements

Build a Flask application that can create and validate forms with flexible CSRF settings. The application should:

  1. Form Factory Endpoint: Create a POST endpoint /api/configure-form that accepts JSON configuration and returns form validation results

    • Accept configuration with enable_csrf boolean field
    • When enable_csrf is true, the form should validate CSRF tokens
    • When enable_csrf is false, the form should bypass CSRF validation
    • Return JSON response with validation status and any errors
  2. Form Definition: Create a simple registration form with:

    • username field (required, string)
    • email field (required, string)
    • Both fields should use standard validators
  3. Request Handling: The endpoint should:

    • Parse the configuration from request JSON
    • Create form instance with appropriate CSRF settings
    • Validate the form
    • Return structured response: {"valid": boolean, "errors": object}

Test Cases

  • The endpoint accepts form data with CSRF enabled and validates successfully when token is present @test
  • The endpoint accepts form data with CSRF disabled and validates successfully without token @test
  • The endpoint properly validates required fields regardless of CSRF setting @test

@generates

API

from flask import Flask, request, jsonify

app = Flask(__name__)
app.config['SECRET_KEY'] = 'test-secret-key'

@app.route('/api/configure-form', methods=['POST'])
def configure_form():
    """
    Create and validate a form with configurable CSRF protection.

    Request JSON:
    {
        "enable_csrf": bool,
        "username": str,
        "email": str,
        "csrf_token": str (optional)
    }

    Response JSON:
    {
        "valid": bool,
        "errors": dict
    }
    """
    pass

if __name__ == '__main__':
    app.run(debug=True)

Dependencies { .dependencies }

Flask-WTF { .dependency }

Provides form handling and CSRF protection for Flask applications.

Version

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