如何在 django 中使用 less css?

发布于 2024-12-24 22:06:17 字数 338 浏览 3 评论 0 原文

我正在使用 twitter bootstrap 和 django。我已经使用 pip 需求文件处理了我的依赖项。

我有两个问题:

  1. 在开发过程中如何使用 less ,以便在编辑我的 less 文件之一时它会被编译?
  2. 作为部署的一部分,如何创建某种构建脚本来压缩和组合我的 JS 并从 Less 生成 CSS?

我编写了一个自定义构建脚本,用于创建 virtualenv、运行“pip install -rrequirements.txt”、djangosyncdb、djangomigrate,然后开始。

减少集成的最简单方法是什么?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说不完的你爱 2024-12-31 22:06:17
  1. 安装django-static-precompiler:< /p>

  2. 运行pip 安装 django-static-precompiler

  3. static_precompiler 添加到 INSTALLED_APPS

  4. 安装 lessc 可执行文件,通过包管理器或运行 npm install lessnpm 是节点包管理器,它应该是可发行版安装的,最后使用度假村)

  5. 在模板中使用 less

  6. 加载模板标签{% load less %}

  7. 使用较少的模板标签

请注意,默认情况下,编译后的文件会保存到 STATIC_ROOT 下的 COMPILED 文件夹中(如果您选择的话,则为 MEDIA_ROOT 下的文件夹)没有设置中的STATIC_ROOT)。您可以使用STATIC_PRECOMPILER_OUTPUT_DIR设置更改此文件夹名称。有关更多详细信息,请参阅文档

我没有亲自尝试过,但我知道 django-compressor 也支持 less 。

  1. Install django-static-precompiler:

  2. Run pip install django-static-precompiler

  3. Add static_precompiler to INSTALLED_APPS

  4. 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)

  5. Use less in templates:

  6. Load the template tag: {% load less %}

  7. 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.

云醉月微眠 2024-12-31 22:06:17

所选答案现已过时:不再维护django-less(如指定)它的 pypi 页面),开发人员建议使用 django-static-precompiler 代替。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文