Skip to content

Django application that substitues runserver command with the one that notifies livereload server about template changes, and development server restarts

License

Notifications You must be signed in to change notification settings

n4bz0r/django-livereload-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-livereload-notifier

About

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).

Features

  • Livereload server notification on template files changes
  • Livereload server notification on development server restart
  • Middleware for injecting livereload <script> tags

Alternatives

Reasoning

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.

Installation

Requirements

  • Python 3.6+ (mostly because of f-strings). Open an issue if you think an older version should really be supported
  • Django 2+

Package installation

pip install git+https://github.com/n4bz0r/django-livereload-notifier.git

Or if you want to specify the exact version (commit):

pip install git+https://github.com/n4bz0r/django-livereload-notifier.git@83a163b7e48eaf94e44b8851bd1a8b0398d3da1d

requirements.txt string:

git+https://github.com/n4bz0r/django-livereload-notifier.git@83a163b7e48eaf94e44b8851bd1a8b0398d3da1d

The package is not yet available on PyPi.

Registering the application

Add 'livereload.django' application to Django INSTALLED_APPS setting.

Registering the script injecting middleware

Add 'livereload.django.middleware.LiveReloadScriptInjector' to Django MIDDLEWARE setting before the 'django.contrib.staticfiles' (if used).

Running

Simply use manage.py runserver like you usually would. List of available options you can find in the following section.

Configuration

Settings

  • LIVERELOAD_HOST — livereload server host. Default: 'localhost'
  • LIVERELOAD_PORT — livereload server port. Default: 35729

Command-line options

  • --livereload-host — livereload server host. Overrides LIVERELOAD_HOST setting if specified
  • --livereload-port — livereload server port. Overrides LIVERELOAD_PORT setting if specified

Links

Livereload server implementations

Thanks

About

Django application that substitues runserver command with the one that notifies livereload server about template changes, and development server restarts

Topics

Resources

License

Stars

Watchers

Forks

Languages