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</code>

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:
    INSTALLED_APPS = (
    # other apps..
    'compressor',
    'static-precompiler',
    )
    
  • Add settings for django-static-precompiler (more details here):
    STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'static_precompiler.finders.StaticPrecompilerFinder',
    )
    STATIC_PRECOMPILER_COMPILERS = (
    'static_precompiler.compilers.LESS',
    )
  • Add these settings for django-compressor settings (more details here and here):
    STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
    )
    COMPRESS_PRECOMPILERS = (
    ('text/less', 'lessc {infile} {outfile}'),
    )
    INTERNAL_IPS = ('127.0.0.1',) # enables local compiling
    COMPRESS_ENABLED = True # defaults to opposite of DEBUG
    COMPRESS_OFFLINE = True # allow pre-compression of files
Add Comment Register



Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>