~/ FScode

Django Browser-Reload

  1. Install Dependencies:

Install django-browser-reload:

python -m pip install django-browser-reload
  1. 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",
    # ...
]
  1. 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.
  1. Add Middleware:

In your MIDDLEWARE settings, add this line after other middleware (e.g., GZipMiddleware):

MIDDLEWARE = [
    # ...
    "django_browser_reload.middleware.BrowserReloadMiddleware",
    # ...
]

DEBUG = True

The middleware inserts a script tag on HTML responses when DEBUG is True, enabling automatic reloading.

  1. All Set!

Now, when you save changes to Python files, HTML, or CSS files, your browser will automatically reload to reflect those changes.

logo