django-compressor, LESS, and collectstatic
I like LESS. I like to compile it with django-compressor. I like to do this in development. But, this means I have to run python manage.py collectstatic
every time I make a change to my project.less file.
Well, I found this Python program called watchdog, which I pip installed, and now I can run the following command to do it for me:
$ watchmedo shell-command -R -c "python manage.py collectstatic --noinput" static
The option -R
tells it to watch files recursively, and -c
is the command to run when files change. The argument "static" is the path to my static directory, because I'm running it from one directory above my static files. You can run it without the argument if you do so from your static directory.
If you don't keep your static files all in one place, there is also an option --patterns
, but it only seems to match against the filename, not including the directory. I tried --patterns="static/*"
first, before I realized there was a better way, but it didn't do anything. So, you would have to do something like the following in your project root:
$ watchmedo --patterns="*.less" -R -c "python manage.py collecstatic --noinput"
If you think I'm crazy because you don't have to run collectstatic, please tell me what I'm doing wrong.
Written by katy lavallee
Related protips
1 Response
Well this is great patch to a big hole in django static files logic. Nowadays, in a world with sass and less, if u do not use django built-in server u r basically f*cked :)