45๐
-
Install django-static-precompiler:
-
Run
pip install django-static-precompiler
-
Add
static_precompiler
to INSTALLED_APPS -
Install lessc executable, either via your package manager or run
npm install less
(npm is node package manager, which should be distro-installable, use at last resort) -
Use less in templates:
-
Load the template tag:
{% load less %}
-
Use less template tag:
<link rel="stylesheet" href="{{ STATIC_URL}}{% less "path/to/styles.less" %}" />
Note that by default compiled files are saved into COMPILED
folder under your STATIC_ROOT
(or MEDIA_ROOT
if you have no STATIC_ROOT
in your settings). You can change this folder name with STATIC_PRECOMPILER_OUTPUT_DIR
setting. See the documentation for further details.
I didnโt try it personally but i know that django-compressor also supports less.
15๐
The selected answer is now out of date: django-less
is no longer being maintained (as specified on its pypi page), and the developer suggests using django-static-precompiler instead.
- [Django]-Unsupported operand type(s) for *: 'float' and 'Decimal'
- [Django]-Django Rest Framework Token Authentication
- [Django]-How to use python2.7 pip instead of default pip