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.2.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.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_hot_reload-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 60bcec0a0def881d48500738ca961cdccd17138e82b136b91969db90449c4c03
MD5 444ef2aaa2b057398017843bbcd647ad
BLAKE2b-256 b54e005e94deaf2933fcce90d63116b950c829e1c4ed11dc5305c6fbe78fa8de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_hot_reload-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0b72d1ea446d7adca3876777cd3bb531188e659b062a8ad8090677e314e3e5
MD5 dbca41925786461f8450b0cd553e1d52
BLAKE2b-256 644f7e98df1a57c5a45bc66d69898c566d284dc6205089a14c2b43457a53c1a7

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