How to automatically reload Django when files change? How to automatically reload Django when files change? python python

How to automatically reload Django when files change?


You don't need a browser extension to accomplish auto refreshes. Take a look at https://github.com/tjwalch/django-livereload-server.

I posted a more extensive answer about this at https://stackoverflow.com/a/36961244/2950621

It works by using a manage.py command (server) to monitor your .js and other static files. The server sends a signal to the browser via websockets. There is some client-side code injected on every page. The injected code responds to the signal and refresh the browser.


Install this django app:

pip install django-livesync

On your django settings file add something like:

INSTALLED_APPS = (    '...',    'livesync',    'django.contrib.staticfiles',    '...',)MIDDLEWARE_CLASSES = (    'livesync.core.middleware.DjangoLiveSyncMiddleware',)

Beware to register 'livesync' before 'django.contrib.staticfiles' if you are using it.

Now, just start your development server:

python manage.py runserver

Check this out for more details: https://github.com/fabiogibson/django-livesync


Using python manage.py runserver is what most use. You'll have to use another tool like: http://livejs.com/ to refresh the browser itself since Django really isn't aware of it.