【发布时间】:2011-02-23 11:16:55
【问题描述】:
在我的 django 网站上,我想为我们最好的客户和老板提供几个主题。所以我很快创建了以下内容。 - 我很高兴我能相处融洽,但有一些肮脏的技巧我想用我要求的很好的解决方案来消除。
这是我的秘诀
base.html 说(小心——丑!)
{% ifequal theme "0" %}
{% include "base_d0.html" %}
{% endifequal %}
{% ifequal theme "1" %}
{% include "base_d1.html" %}
{% endifequal %}
{% ifequal theme "2" %}
{% include "base_d2.html" %}
{% endifequal %}
然后我将所有常见 css 和 js 的子目录保存在 MEDIA 目录中
并创建子目录
static/
d0/ ( all theme 0 stuff )
css/
js/
d1/ ( all theme 1 stuff )
css/
js/
...
css/
(all common css)
js/
(all common js)
我的控制器有一个切换设计的方法,当前一个存储在 cookie 中。它会在每个请求和模板中检查 PREFIX_STATIC 上下文变量,对应于 /mypathto/static/d0 resp. +d1 +d2,当然我必须发明一个 COMMON_STATIC var。并且为 base.html 开关设置了主题变量。
当然,我什至在开始之前就用谷歌搜索过,但发现很难找到好的搜索词(因为我希望有很多好的资源)
【问题讨论】:
-
我承认我没有检查块是否已填满,它看起来不像那样工作。我的问题是:如何让 django 在几个 base.html 之间进行选择