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

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.

Install with Tessl CLI

npx tessl i tessl/pypi-flask-wtf

tile.json