[英]What's the most elegant way to convert requests' response to DRF response in Django?
[英]Django + twitter bootstrap + github what's the most elegant way to do this?
您可以在django中安装此应用程序并使用
pip install -U django-staticfiles-bootstrap
./manage.py collectstatic
将最新的bootstrap代码拉入您的项目:)
这可能不是你想要的,因为这个策略中有一个丑陋的部分,但值得一提的是恕我直言。
这是您的site_base.html
模板可以包含的方式:
{% if debug %}
<link rel="stylesheet" type="text/css" href="{% static 'autocomplete_light/style.css' %}" />
<link href="{{ STATIC_URL }}bootstrap/less/bootstrap.less" charset="utf-8" type="text/less" rel="stylesheet">
<script type="text/javascript">less = {}; less.env = 'development';</script>
<script type="text/javascript" src="{{ STATIC_URL }}less.js" ></script>
{% else %}
{% compress css %}
<link rel="stylesheet" type="text/css" href="{% static 'autocomplete_light/style.css' %}" />
<link href="{{ STATIC_URL }}bootstrap/less/bootstrap.less" charset="utf-8" type="text/less" rel="stylesheet">
{% endcompress %}
{% endif %}
好吧,这是丑陋的部分:它不是很干......但它确实很有用。 如您所见,您需要调试上下文处理器 。
这就是您的设置的样子:
COMPRESS_PRECOMPILERS = (
('text/less', 'recess --compile {infile} > {outfile}'),
)
注意:当我这样做时,bootstrap只编译在凹陷较少的编译器上。 也许现在支持其他编译器,但我不打赌它。
要直接从repo重用bootstrap,请使用git子模块 。
假设我们创建了一个custom.less
脚本,它应该能够重用bootstrap的东西,即。 变量,类,mixins等。
我们现在遇到一个问题:编译器必须同时解析bootstrap的东西和custom.less
。 否则,在编译custom.less
时,编译器怎么能知道bootstrap的变量呢?
因此,您可以在bootstrap.less
导入custom.less
,但这会导致在repo之外修改文件(请记住:bootstrap.less来自子模块)。
解决方案:创建一个master.less
,它导入bootstrap/less/bootstrap.less
和custom.less
。 不要忘了链接master.less
而不是bootstrap.less
在site_base.html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.