Skip to content

al3xsus/js-light-python-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Flask + HTMX Demo Application

A comprehensive demonstration of HTMX capabilities with Flask and Jinja2. This modern web application showcases how to build dynamic, interactive user interfaces without writing JavaScript.

πŸ“‹ Features

This application demonstrates the following HTMX features:

🎯 Basic Operations

  • GET/POST Requests - Simple AJAX requests without page reloads
  • Dynamic Content Loading - Fetch and display content on demand
  • Debouncing - Optimize requests with input delays

βœ… Task Management (CRUD)

  • Create - Add new tasks with inline forms
  • Read - Display and filter tasks dynamically
  • Update - Inline editing with server validation
  • Delete - Confirmation dialogs before deletion
  • Real-time Filtering - Filter by status (all/active/completed)

πŸ” Search & Navigation

  • Live Search - Search-as-you-type with debouncing
  • Infinite Scroll - Automatic pagination without buttons
  • Loading Indicators - Visual feedback during requests

πŸ“ Forms & Validation

  • Real-time Validation - Server-side validation on field blur
  • Inline Feedback - Show errors/success next to fields
  • Form Submission - AJAX form posts with response handling

πŸ”„ Real-time Updates

  • Polling - Auto-refresh content at intervals
  • Live Notifications - Check for updates periodically
  • Server Status Monitor - Real-time dashboard metrics

πŸͺŸ Advanced Features

  • Modal Dialogs - Dynamic content loading in modals
  • Out-of-Band Swaps (OOB) - Update multiple page areas from one request
  • CSS Transitions - Smooth animations with HTMX classes
  • Loading States - Various loading indicators and disabled states
  • Server-Sent Events (SSE) - Real-time server push updates

πŸ› οΈ Technology Stack

  • Python 3.x - Backend language
  • Flask 3.0 - Web framework
  • Jinja2 3.1 - Template engine
  • HTMX 1.9 - Frontend interactivity
  • Modern CSS - Custom styling with CSS variables

πŸ“¦ Installation

  1. Clone the repository
git clone https://github.com/al3xsus/js-light-python-app.git
cd js-light-python-app
  1. Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run the application
python app.py
  1. Open your browser Navigate to http://localhost:5000

πŸ“– Usage

The application consists of multiple demo pages, each showcasing different HTMX features:

  • Home (/) - Overview of all features with navigation
  • Basic (/basic) - Fundamental HTMX requests and triggers
  • Tasks (/tasks) - Complete CRUD task management system
  • Search (/search) - Live search and infinite scroll
  • Forms (/forms) - Form validation with server-side checks
  • Polling (/polling) - Auto-refresh and live notifications
  • Modal (/modal) - Dynamic modals and OOB swaps
  • Transitions (/transitions) - CSS animations and loading states
  • SSE (/sse) - Server-sent events for real-time updates

🎨 HTMX Attributes Demonstrated

Attribute Purpose Example Page
hx-get Issue GET request Basic, Search
hx-post Issue POST request Tasks, Forms
hx-put Issue PUT request Tasks (update)
hx-delete Issue DELETE request Tasks (delete)
hx-target Specify where to load response All pages
hx-swap Control how content is swapped All pages
hx-trigger Specify what triggers request Basic, Search, Polling
hx-indicator Show loading indicator Search, Transitions
hx-swap-oob Out-of-band swaps Modal
hx-disabled-elt Disable elements during request Transitions
hx-include Include additional elements Basic

πŸ—οΈ Project Structure

js-light-python-app/
β”œβ”€β”€ app.py                 # Flask application with all routes
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ static/
β”‚   └── css/
β”‚       └── style.css     # Custom CSS styling
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html         # Base template with navigation
β”‚   β”œβ”€β”€ index.html        # Home page
β”‚   β”œβ”€β”€ basic.html        # Basic HTMX examples
β”‚   β”œβ”€β”€ tasks.html        # Task management
β”‚   β”œβ”€β”€ search.html       # Search and infinite scroll
β”‚   β”œβ”€β”€ forms.html        # Form validation
β”‚   β”œβ”€β”€ polling.html      # Polling and auto-refresh
β”‚   β”œβ”€β”€ modal.html        # Modal and OOB swaps
β”‚   β”œβ”€β”€ transitions.html  # CSS transitions
β”‚   β”œβ”€β”€ sse.html          # Server-sent events
β”‚   └── partials/         # Reusable template fragments
β”‚       β”œβ”€β”€ task_item.html
β”‚       β”œβ”€β”€ task_edit.html
β”‚       β”œβ”€β”€ task_delete_confirm.html
β”‚       β”œβ”€β”€ task_list.html
β”‚       β”œβ”€β”€ user_list.html
β”‚       β”œβ”€β”€ user_infinite.html
β”‚       β”œβ”€β”€ server_status.html
β”‚       └── modal_content.html
└── README.md             # This file

πŸ’‘ Key Concepts

Why HTMX?

HTMX allows you to:

  • Build modern UIs without writing JavaScript
  • Keep logic on the server where it belongs
  • Use hypermedia as the engine of application state
  • Progressively enhance existing applications
  • Reduce complexity and bundle sizes

Why Flask?

Flask is:

  • Lightweight and flexible
  • Perfect for serving HTML fragments
  • Easy to learn and use
  • Has excellent template support with Jinja2

Pattern: Partial Templates

This app uses the "partial template" pattern where:

  1. Server returns small HTML fragments
  2. HTMX swaps them into the DOM
  3. Each fragment is a reusable Jinja2 template
  4. Logic stays server-side (Python)

πŸ”§ Development

Adding New Features

  1. Add a route in app.py
  2. Create a template in templates/
  3. Create partials in templates/partials/ if needed
  4. Add navigation link in base.html
  5. Test the feature

Customizing Styles

Edit static/css/style.css to customize:

  • Color scheme (CSS variables in :root)
  • Component styles
  • Animations and transitions
  • Responsive breakpoints

πŸ“š Learning Resources

🀝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

πŸ“„ License

This project is open source and available for educational purposes.

🎯 Next Steps

Try these challenges to extend your learning:

  1. Add user authentication
  2. Connect to a real database
  3. Add file upload functionality
  4. Implement drag-and-drop sorting
  5. Add WebSocket support
  6. Create a chat application

Built with ❀️ using Python, Flask, and HTMX

About

Just a simple app to show power of Python + HTMX

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors