{"id":5904,"library":"django-browser-reload","title":"Django Browser Reload","description":"django-browser-reload is a Django application that automatically refreshes your web browser during development when changes are detected in Python code, templates, or static files. It helps improve the development workflow by eliminating manual browser reloads. The current version is 1.21.0, and it actively supports Python versions 3.9 to 3.14 and Django versions 4.2 to 6.0. It is actively maintained.","status":"active","version":"1.21.0","language":"en","source_language":"en","source_url":"https://github.com/adamchainz/django-browser-reload","tags":["django","development","hot reload","browser reload","static files","templates","middleware","dx"],"install":[{"cmd":"pip install django-browser-reload","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for static file detection and serving assets.","package":"django.contrib.staticfiles","optional":false}],"imports":[{"note":"Add to INSTALLED_APPS in settings.py","symbol":"django_browser_reload","correct":"INSTALLED_APPS = [\n    # ...\n    'django_browser_reload',\n    # ...\n]"},{"note":"Add to MIDDLEWARE in settings.py, typically after other encoding middleware like GZipMiddleware.","symbol":"BrowserReloadMiddleware","correct":"MIDDLEWARE = [\n    # ...\n    'django_browser_reload.middleware.BrowserReloadMiddleware',\n    # ...\n]"},{"note":"Include app URLs in your project's main urls.py.","symbol":"django_browser_reload.urls","correct":"from django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('__reload__/', include('django_browser_reload.urls')), # Only in DEBUG mode\n]"},{"note":"Alternative to middleware for injecting the reload script on specific pages. Only renders when DEBUG is True.","symbol":"reload_script (template tag)","correct":"{% load django_browser_reload %}\n...\n<body>\n    ...\n    {% reload_script %}\n</body>"}],"quickstart":{"code":"import os\nfrom pathlib import Path\nfrom django.conf import settings # Import settings to check DEBUG\nfrom django.urls import include, path\n\n# --- settings.py (abbreviated) ---\n# Make sure DEBUG is True for development\nDEBUG = True\n\n# Required for static files\nINSTALLED_APPS = [\n    # ... existing Django apps\n    'django.contrib.staticfiles',\n    'django_browser_reload',\n]\n\n# Add BrowserReloadMiddleware to your MIDDLEWARE list\n# It should come after any middleware that encodes the response (e.g., GZipMiddleware)\nMIDDLEWARE = [\n    # ... existing middleware\n    'django_browser_reload.middleware.BrowserReloadMiddleware',\n]\n\n# --- urls.py (abbreviated) ---\n# Include django-browser-reload's URLs\nurlpatterns = [\n    path('admin/', admin.site.urls),\n]\n\n# Conditionally add the reload URLs in DEBUG mode\nif settings.DEBUG:\n    urlpatterns += [\n        path(\"__reload__/\", include(\"django_browser_reload.urls\")),\n    ]\n\n# To run:\n# 1. Ensure you have a Django project set up.\n# 2. Add the above settings and URL patterns.\n# 3. Run: python manage.py runserver\n# 4. Open your browser to http://127.0.0.1:8000/ and modify a Python file, template, or static file.","lang":"python","description":"To quickly set up `django-browser-reload`, install it via pip, then add `django_browser_reload` to your `INSTALLED_APPS` and `BrowserReloadMiddleware` to your `MIDDLEWARE` in `settings.py`. Crucially, `DEBUG` must be `True`. Finally, include `django_browser_reload.urls` in your project's main `urls.py`, ideally wrapped in a `if settings.DEBUG:` block. Once configured, run `python manage.py runserver`, and your browser will automatically refresh on code, template, or static file changes."},"warnings":[{"fix":"Ensure `django_browser_reload.middleware.BrowserReloadMiddleware` is listed after `GZipMiddleware` or similar encoding middleware in your `MIDDLEWARE` setting.","message":"The `BrowserReloadMiddleware` must be placed *after* any other middleware that encodes the response, such as Django's `GZipMiddleware`. Incorrect placement can prevent the script from being injected or cause unexpected behavior.","severity":"breaking","affected_versions":"All versions"},{"fix":"Set `DEBUG = True` in your `settings.py` for development. The `__reload__` URL pattern should also ideally be conditional on `settings.DEBUG`.","message":"`django-browser-reload` only operates when `DEBUG = True` in your Django settings. It is a development-only tool and will not function in production environments.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure browsers used for development are modern and support `SharedWorker` (Chrome, Edge, Firefox, Opera, and Safari 16+). The library provides graceful degradation if SharedWorker is unavailable, falling back to per-tab reloading.","message":"The library utilizes `SharedWorker` for efficient multi-tab reloading, which was not supported by Safari prior to version 16 (released September 2022). Older Safari versions may not experience automatic reloads.","severity":"gotcha","affected_versions":"< 1.13.0 (for Safari compatibility specifics), generally all versions for browser requirement."},{"fix":"Avoid using the `--nothreading` option with `runserver` when using `django-browser-reload`.","message":"Using `python manage.py runserver --nothreading` will prevent `django-browser-reload` from functioning correctly, as it relies on threads to stream events indefinitely.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult Django 5.1 documentation for `LoginRequiredMiddleware` configuration to whitelist the `__reload__` path, e.g., by using `login_not_required` attributes on the URL pattern or view.","message":"When using `django-browser-reload` with Django 5.1's `LoginRequiredMiddleware`, you may need to explicitly configure `login_not_required` for the `__reload__` URL path to ensure it can be accessed without authentication.","severity":"gotcha","affected_versions":"Django 5.1+"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}