如何使用较少的css与django?

时间:2022-03-21 02:41:13

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

我用的是推特和django。我已经用pip需求文件处理了我的依赖项。

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. 如何在开发过程中减少使用,以便在编辑一个较少的文件时编译?
  3. 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?
  4. 如何创建某种构建脚本,将压缩和组合我的JS,并从更少的部署中生成CSS ?

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.

我编写了一个自定义构建脚本,创建一个virtualenv,运行pip安装-r需求。txt', django syncdb, django迁移然后离开。

What's the easiest way of integrating less into this?

最简单的积分方法是什么?

Thanks

谢谢

2 个解决方案

#1


42  

  1. Install django-static-precompiler:

    安装django-static-precompiler:

    1. Run pip install django-static-precompiler
    2. 运行pip安装django-static-precompiler
    3. Add static_precompiler to INSTALLED_APPS
    4. 添加static_precompiler 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)

    安装lessc可执行文件,可以通过您的包管理器,也可以通过运行npm更少地安装(npm是节点包管理器,应该是可扩展安装的,最后使用)

  3. Use less in templates:

    使用更少的模板:

    1. Load the template tag: {% load less %}
    2. 加载模板标签:{% Load less %}
    3. Use less template tag: <link rel="stylesheet" href="{{ STATIC_URL}}{% less "path/to/styles.less" %}" />
    4. 使用较少的模板标签:

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.

注意,默认情况下,已编译文件被保存到STATIC_ROOT(或MEDIA_ROOT,如果您的设置中没有STATIC_ROOT)下的编译文件夹中。可以使用static_precompile er_output_dir设置更改此文件夹名称。有关更多细节,请参阅文档。

I didn't try it personally but i know that django-compressor also supports less.

我并没有亲自尝试,但我知道django压缩器也支持较少。

#2


14  

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(如其pypi页面中指定的那样),开发人员建议使用django静态预编译器。

#1


42  

  1. Install django-static-precompiler:

    安装django-static-precompiler:

    1. Run pip install django-static-precompiler
    2. 运行pip安装django-static-precompiler
    3. Add static_precompiler to INSTALLED_APPS
    4. 添加static_precompiler 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)

    安装lessc可执行文件,可以通过您的包管理器,也可以通过运行npm更少地安装(npm是节点包管理器,应该是可扩展安装的,最后使用)

  3. Use less in templates:

    使用更少的模板:

    1. Load the template tag: {% load less %}
    2. 加载模板标签:{% Load less %}
    3. Use less template tag: <link rel="stylesheet" href="{{ STATIC_URL}}{% less "path/to/styles.less" %}" />
    4. 使用较少的模板标签:

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.

注意,默认情况下,已编译文件被保存到STATIC_ROOT(或MEDIA_ROOT,如果您的设置中没有STATIC_ROOT)下的编译文件夹中。可以使用static_precompile er_output_dir设置更改此文件夹名称。有关更多细节,请参阅文档。

I didn't try it personally but i know that django-compressor also supports less.

我并没有亲自尝试,但我知道django压缩器也支持较少。

#2


14  

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(如其pypi页面中指定的那样),开发人员建议使用django静态预编译器。