Django Browser-Reload
- Install Dependencies:
Install django-browser-reload:
python -m pip install django-browser-reload- Update Django Settings:
Ensure "django.contrib.staticfiles" is in your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
# ...
"django.contrib.staticfiles",
# ...
]Add "django_browser_reload" to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_browser_reload",
# ...
]- Include App URLs:
In your root URL configuration (usually in urls.py), include the app's URLs:
from django.urls import include, path
urlpatterns = [
# ...
path("__reload__/", include("django_browser_reload.urls")),
# ...
]- You can use a different prefix if needed.
- Add Middleware:
In your MIDDLEWARE settings, add this line after other middleware (e.g., GZipMiddleware):
MIDDLEWARE = [
# ...
"django_browser_reload.middleware.BrowserReloadMiddleware",
# ...
]
DEBUG = TrueThe middleware inserts a script tag on HTML responses when DEBUG is True, enabling automatic reloading.
- All Set!
Now, when you save changes to Python files, HTML, or CSS files, your browser will automatically reload to reflect those changes.
