django 站点上的主题切换、模板和 css 文件布局
在我的 django 网站中,我想为我们最好的客户和老板提供几个主题。所以我很快创建了以下内容。 - 我很高兴我能顺利地展示它,但我想通过我向您提出的好的解决方案来消除一些肮脏的黑客行为。
这是我的 hack
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 中。它会针对每个请求进行检查,并在模板中根据 /mypathto/static/d0 resp 检查
当然,我必须发明一个 PREFIX_STATIC
上下文变量。 +d1 +d2COMMON_STATIC
var。并且主题变量也为 base.html 开关设置。
当然,我什至在开始之前就用谷歌搜索过,但发现很难找到好的搜索词(正如我期望的那样,有很多好的资源)
In my django site I want to offer several themes for our best clients and for the boss. So I quickly created the following. - I am glad i got along to present it but there are a few dirty hacks I want to eliminate with nice solutions I ask you for.
Here's my hack
base.html says (take care - ugly!)
{% ifequal theme "0" %}
{% include "base_d0.html" %}
{% endifequal %}
{% ifequal theme "1" %}
{% include "base_d1.html" %}
{% endifequal %}
{% ifequal theme "2" %}
{% include "base_d2.html" %}
{% endifequal %}
Then i kept in MEDIA dir the subdirs for all common css and js
and created subdirs
static/
d0/ ( all theme 0 stuff )
css/
js/
d1/ ( all theme 1 stuff )
css/
js/
...
css/
(all common css)
js/
(all common js)
My controller has a method to switch design, current one is stored in a cookie. It is checked on every request and in template a PREFIX_STATIC
context variable accordingly to /mypathto/static/d0 resp. +d1 +d2
and of course i had to invent a COMMON_STATIC
var. And the theme var is set too for the base.html switch.
Of course i googled even before starting but found it hard to find good search terms (as i expect there are many good resources )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 loader_tags.py Include_Node do_extends 文档:
我在主控制器中将模板更改为 do
而不是并将上下文 var "base" 设置为
theme + "/base.html"
因此,在调用 get_template 之前,
from loader_tags.py Include_Node do_extends doc:
So i changed my templates to do
instead of
and set context var "base" as
theme + "/base.html"
in my main controller before i call get_template