ux scrutiny

ramblings about code and ux

django + less, updated


In a previous post, I described how I configured the hyperkitty django project to use LESS. Briefly, my steps were:
- install django-compressor, django-less, nodejs, npm, and lessc
- update settings.py with configuration settings for django-compressor and django-less
- restart webserver

However, it turns out some of those steps are a bit outdated. First, PyPI says that django-less is not maintained and suggests using django-static-precompiler instead. Second, while LESS suggests that the easiest way to install the compiler is via npm, it is just as easy to install the LESS compiler via nodejs-less. So here are my updated steps for configuring a django project to use LESS:

pip install django-compressor
pip install django-static-precompiler
sudo yum install nodejs-less # installs lessc

I also realized that my settings.py needed to be updated too. I was previously using DEBUG=TRUE and, under that case, everything worked fine. But when I switched over to DEBUG=FALSE, I noticed a few extra settings needed to be added. So, for the sake of completeness, here are all the changes I made to settings for the hyperkitty project.

  • Add settings to INSTALLED_APPS:
    # other apps..
  • Add settings for django-static-precompiler (more details here):
    # other finders..
  • Add these settings for django-compressor settings (more details here and here):
    # other finders..
    ('text/less', 'lessc {infile} {outfile}'),
    INTERNAL_IPS = ('',) # enables local compiling
    COMPRESS_ENABLED = True # defaults to opposite of DEBUG
    COMPRESS_OFFLINE = True # allow pre-compression of files
Add Comment Register

Leave a Reply

Required fields are marked *.