.cursorrules Htmx Flask

HTMX with Flask Development Guidelines

A set of best practices and instructions for integrating HTMX with Flask, focusing on efficient and secure development:

HTMX and Flask Best Practices

  • Use Flask’s render_template for server-side rendering and Flask-WTF for form handling.
  • Utilize url_for for generating URLs and jsonify for JSON responses.
  • Implement Flask-SQLAlchemy for database operations and Flask’s Blueprint for modular applications.

Folder Structure

Organize code into a structured directory:

textapp/
  templates/
  static/
    css/
    js/
  models/
  routes/
  __init__.py
config.py
run.py

Additional Instructions

  • Use Jinja2 templating with HTMX attributes.
  • Implement proper CSRF protection using Flask-WTF.
  • Utilize Flask’s request object for handling HTMX requests and Flask-Migrate for database migrations.
  • Follow Flask’s application factory pattern and use environment variables for configuration.

Overview of .cursorrules prompt

This prompt provides guidelines for integrating HTMX with Flask, focusing on best practices for dynamic web development. It emphasizes using Flask’s templating, form handling, and database management features alongside HTMX’s interactive capabilities. Key aspects include proper CSRF protection, modular application design, and efficient error handling, ensuring that applications are both interactive and secure. By following these guidelines, developers can build responsive web applications that leverage the strengths of both HTMX and Flask.

Updated: March 15, 2025
This prompt outlines integrating HTMX with Flask for dynamic web development, emphasizing best practices for templating, form handling, and security.
Usefull for: