Socket
Book a DemoInstallSign in
Socket

strynova-dj-hotreload

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strynova-dj-hotreload

Add hot reloading to Django apps.

pipPyPI
Version
0.4
Maintainers
1

Strynova Django Hot Reload

Adds browser hot reloading to a Django project. When you make changes to your HTML, CSS, or JavaScript files, the browser will automatically reload to show the changes.

Installation

pip install strynova-dj-hotreload

Usage

  • Add strynova_dj_hotreload to your INSTALLED_APPS in your Django settings.py file:
INSTALLED_APPS = [
    # ... other apps
    'strynova_dj_hotreload',
]
  • Add the hot reload JavaScript to your base template:
{% load strynova_hot_reload %}
<!DOCTYPE html>
<html>
<head>
    <!-- Your head content -->
    {% hot_reload_js %}
</head>
<body>
    <!-- Your body content -->
</body>
</html>
  • Run your Django server:
python manage.py runserver

Now your Django project has browser hot reloading! Make changes to your HTML, CSS, or JavaScript files, and the browser will automatically reload to show the changes.

Configuration

You can configure the hot reload functionality in your Django settings:

# Enable hot reload even in production (not recommended)
STRYNOVA_HOT_RELOAD_FORCE = True

# Configure WebSocket server
STRYNOVA_HOT_RELOAD_HOST = '127.0.0.1'  # Default
STRYNOVA_HOT_RELOAD_PORT = 8765  # Default

# Specify which directories to watch (by default, it watches all template and static directories)
STRYNOVA_HOT_RELOAD_DIRS = [
    '/path/to/templates',
    '/path/to/static',
]

# Specify which file types to watch
STRYNOVA_HOT_RELOAD_FILE_TYPES = ['html', 'css', 'js']  # Default

# How often to check for changes (in seconds)
STRYNOVA_HOT_RELOAD_INTERVAL = 1.0  # Default

How it works

  • When the Django server starts, a file watcher thread is created to monitor your template and static files.
  • A WebSocket server is started to communicate with the browser.
  • The {% hot_reload_js %} template tag adds a JavaScript client to your page that connects to the WebSocket server.
  • When the file watcher detects changes, it sends a message to the WebSocket server.
  • The WebSocket server notifies all connected clients (browsers).
  • The JavaScript client receives the notification and reloads the page.

Requirements

  • Django >= 3.2
  • Python 3
  • websockets package (installed automatically)

Keywords

django

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts