django-livereload-server installation

98 views Asked by At

I am new to django and trying to install django-livereload-server

Somewhere in the installation guide, it says:

You need to inject the loading of the livereload javascript. You can do this in one of two ways:

Through middleware by adding 'livereload.middleware.LiveReloadScript' to MIDDLEWARE_CLASSES (probably at the end):

MIDDLEWARE_CLASSES = (
    ...
    'livereload.middleware.LiveReloadScript',
)

Through a templatetag in your base.html (or similar) template:

{% load livereload_tags %}
...
{% livereload_script %}

For the first solution, I've noticed there is no MIDDLEWARE_CLASSE = () tuple in the settings.py file (django 4.2.4). There is only a MIDDLEWARE_CLASSE = [] list, and putting 'livereload.middleware.LiveReloadScript' in it does not work. (In this case Live reload detects changes, but can't reload localhost:8000. It says Reload 0 waiters: None)

So, where should I put 'livereload.middleware.LiveReloadScript' to get it to work?

If I want to use the second solution, what are the steps? Cause I don't see the base.html in my project/ app. Should I create it myself?

Appreciate any help!

Using: VSCode, django, enve,

Installed packages:

asgiref                  3.7.2
beautifulsoup4           4.12.2
Django                   4.2.4
django-livereload-server 0.4
dnspython                2.4.2
et-xmlfile               1.1.0
greenlet                 2.0.2
pip                      23.2.1
setuptools               63.2.0
six                      1.16.0
soupsieve                2.4.1
sqlparse                 0.4.4
tornado                  6.3.3
typing_extensions        4.7.1
tzdata                   2023.3

Update: It started to work with the mentioned settings after a while. I couldn't find the reason, but it works properly now.

1

There are 1 answers

0
michjnich On
  1. settings.py should contain a value for MIDDLEWARE. Anything else is wrong.

It used to be MIDDLEWARE_CLASSES but this changed a while back (not sure which version).

  1. templatetags do not need to be used in base.html - where you put them entirely depends on where you need them. Putting them in a base template that everything else inherits from would be the easiest way to ensure they were available in all templates though.

Side note: It sounds a little as though you should really take a step back and do a django tutorial - the settings.py file and how templates work are basics. I can recommend the Djangogirls tutorial as being very good.

https://tutorial.djangogirls.org/en/

Edit: I added a PR to update the docs on the package so that it is correct going forward: https://github.com/tjwalch/django-livereload-server/pull/67 . Not quite sure how active that project is though ...