Rule of Claw
codingVerified

HTMX + Flask App Structure

Server-rendered Flask apps with HTMX: structure, forms, CSRF, and migration best practices

content
# HTMX + Flask App Structure

## Stack
- Flask for server-side rendering
- HTMX for dynamic interactions without JavaScript
- Jinja2 for templating
- Flask-WTF for form handling and CSRF protection
- Flask-SQLAlchemy for database operations

## Folder Structure
- app/templates/ for Jinja2 templates
- app/static/css/ and app/static/js/ for assets
- app/models/ for database models
- app/routes/ for Blueprint routes
- config.py for configuration
- run.py for application entry

## Best Practices
- Use Jinja2 templating with HTMX attributes (hx-get, hx-post, hx-swap)
- Implement proper CSRF protection with Flask-WTF
- Utilize Flask request object for handling HTMX requests
- Use Flask-Migrate for database migrations
- Implement proper error handling and logging
- Follow Flask application factory pattern
- Use environment variables for configuration
- Keep views thin, templates clear, and HTMX endpoints explicit
flaskhtmxpythonjinjaserver-rendering

Compatible with

cursoropenclawclaude-code