Django-livereload-notifier is an application that substitutes Django runserver command
with the one that keeps track of template files changes, and sends a request to a livereload
server when files in those directories are modified or when development server is restarted.
There is also a convenient middleweare that injects livereload <script> tag into all pages.
The client-side script should be provided by a livereload server (it usually is).
- Livereload server notification on template files changes
- Livereload server notification on development server restart
- Middleware for injecting livereload
<script>tags
Before making my own thing, I tried similar solutions, but they didn't work exactly as I expected:
- specified in settings livereload server host and port weren't used in script injecting middleware making it impossible to connect from a different device
- static file changes weren't registered by livereload server sometimes
- directories specified in command-line options weren't watched by livereload server
- template changes weren't watched
Tired of tinkering with existing solutions to no avail, I looked into the source code of Fantomas42's solution, and ended up rewriting the entire thing to my liking.
- Python 3.6+ (mostly because of
f-strings). Open an issue if you think an older version should really be supported - Django 2+
pip install git+https://github.com/n4bz0r/django-livereload-notifier.gitOr if you want to specify the exact version (commit):
pip install git+https://github.com/n4bz0r/django-livereload-notifier.git@83a163b7e48eaf94e44b8851bd1a8b0398d3da1drequirements.txt string:
git+https://github.com/n4bz0r/django-livereload-notifier.git@83a163b7e48eaf94e44b8851bd1a8b0398d3da1d
The package is not yet available on PyPi.
Add 'livereload.django' application to Django INSTALLED_APPS setting.
Add 'livereload.django.middleware.LiveReloadScriptInjector' to Django MIDDLEWARE setting
before the 'django.contrib.staticfiles' (if used).
Simply use manage.py runserver like you usually would. List of available options you can
find in the following section.
LIVERELOAD_HOST— livereload server host. Default:'localhost'LIVERELOAD_PORT— livereload server port. Default:35729
--livereload-host— livereload server host. OverridesLIVERELOAD_HOSTsetting if specified--livereload-port— livereload server port. OverridesLIVERELOAD_PORTsetting if specified
- Node.js https://github.com/mklabs/tiny-lr
- Node.js (Gulp): https://github.com/vohof/gulp-livereload
- Python: https://github.com/lepture/python-livereload
- Fantomas42 for providing a solid point of reference