Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

python - How to use less css with django?

I'm using twitter bootstrap and django. I've got my dependencies handled with a pip requirements file.

I've got 2 questions:

  1. How can I use less while I'm developing so it'll get compiled when I edit one of my less files?
  2. How can I create some kind of build script that will compress and combine my JS and generate CSS from Less as part of a deployment?

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

question from:https://stackoverflow.com/questions/8726610/how-to-use-less-css-with-django

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Install django-static-precompiler:

    1. Run pip install django-static-precompiler
    2. Add static_precompiler to INSTALLED_APPS
  2. 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)

  3. Use less in templates:

    1. Load the template tag: {% load less %}
    2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...