I'm using twitter bootstrap and django. I've got my dependencies handled with a pip requirements file.
I've got 2 questions:
I've written a custom build script that creates a virtualenv, runs 'pip install -r requirements.txt', django syncdb, django migrate and then off we go.
What's the easiest way of integrating less into this?
Thanks
Aside from the HTML generated by the server, web applications generally need to serve additional files — such as images, JavaScript, or CSS — necessary to render the complete web page. In Django, we refer to these files as “static files”.
Django would be used to match urls with pages. Specifically you would need to create a view that renders a template (here comes the html) and some static files (css, js). If you wont use a database i would suggest that you use flask which does the thing is described above much more easily.
You can use the Django templates in HTML (full or partial), text, XML, JSON, or nearly any other text-based format.
Install django-static-precompiler:
pip install django-static-precompiler
static_precompiler
to INSTALLED_APPSInstall 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 less %}
<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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With