Skip to main content

A Flask extension that provides real-time hot reload for templates, static files and Python code changes

Project description

Flask Hot Reload

English | 中文

English

A Flask extension that automatically refreshes your browser when you make changes to your templates, static files, or Python code.

Installation

pip install flask-hot-reload

Quick Start

from flask import Flask, render_template
from flask_hot_reload import HotReload

app = Flask(__name__)

# Initialize hot reload with custom watch directories
hot_reload = HotReload(app, 
    includes=[
        'templates',  # template directory
        'static',     # static files directory
        '.'          # current directory
    ],
    excludes=[
        '__pycache__',
        'node_modules',
        '.git'
    ]
)

@app.route('/')
def index():
    return render_template('index.html')

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

Features

  • 🔄 Real-time browser refresh on file changes
  • 📁 Monitor multiple directories
  • 🚫 Exclude unwanted directories
  • 🐍 Support for Python file hot reload
  • 📝 Template file hot reload
  • 🎨 Static file hot reload
  • 🔌 WebSocket-based, low latency
  • 🎯 Zero configuration needed

Configuration

Watch Directories

By default, Flask Hot Reload watches the templates and static directories. You can customize the watched directories:

hot_reload = HotReload(app, 
    includes=[
        'templates',
        'static',
        'src',
        'routes'
    ]
)

Exclude Directories

Exclude directories that don't need monitoring:

hot_reload = HotReload(app,
    excludes=[
        '__pycache__',
        'node_modules',
        '.git',
        'venv'
    ]
)

Requirements

  • Python 3.7+
  • Flask 2.0.0+
  • Watchdog 2.1.0+
  • Flask-Sock 0.4.0+
  • Colorama 0.4.6+

中文文档

一个Flask扩展插件,当你修改模板、静态文件或Python代码时,浏览器会自动刷新。

安装

pip install flask-hot-reload

快速开始

from flask import Flask, render_template
from flask_hot_reload import HotReload

app = Flask(__name__)

# 使用自定义监控目录初始化热重载
hot_reload = HotReload(app, 
    includes=[
        'templates',  # 模板目录
        'static',     # 静态文件目录
        '.'          # 当前目录
    ],
    excludes=[
        '__pycache__',  # 排除Python缓存目录
        'node_modules', # 排除npm模块目录
        '.git'         # 排除git目录
    ]
)

@app.route('/')
def index():
    return render_template('index.html')

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

特性

  • 🔄 文件变更时实时刷新浏览器
  • 📁 支持监控多个目录
  • 🚫 可排除不需要监控的目录
  • 🐍 支持Python文件热重载
  • 📝 支持模板文件热重载
  • 🎨 支持静态文件热重载
  • 🔌 基于WebSocket,低延迟
  • 🎯 零配置即可使用

配置

监控目录

默认情况下,Flask Hot Reload 会监控 templatesstatic 目录。你可以自定义监控目录:

hot_reload = HotReload(app, 
    includes=[
        'templates',
        'static',
        'src',
        'routes'
    ]
)

排除目录

排除不需要监控的目录:

hot_reload = HotReload(app,
    excludes=[
        '__pycache__',
        'node_modules',
        '.git',
        'venv'
    ]
)

环境要求

  • Python 3.7+
  • Flask 2.0.0+
  • Watchdog 2.1.0+
  • Flask-Sock 0.4.0+
  • Colorama 0.4.6+

许可证

MIT License

作者

Blake Zhou (1043744584@qq.com)

链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_hot_reload-0.3.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_hot_reload-0.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file flask_hot_reload-0.3.0.tar.gz.

File metadata

  • Download URL: flask_hot_reload-0.3.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for flask_hot_reload-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7afdbd60e1647270b3e5c9e7d8e7cc981af27b05636bcccf4fef29bdb6fa1a95
MD5 afbccee53a4080e4b6847023422e3775
BLAKE2b-256 ff64c14fdf0dc374f2b2aeff0f40188ef57d97442e8d08173be6091208e045da

See more details on using hashes here.

File details

Details for the file flask_hot_reload-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_hot_reload-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c64b70e60467de5c36a5ae735585befca99b199041ee4a10254d3ad7cef1247a
MD5 99f9bedf88d22d95e3244a9f11719da4
BLAKE2b-256 085c708c099f0ae2de7063541458e1bcdd83e206c0887516b643ab7e7614934f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page