将变量传递给Django中的CSS文件 [英] Passing variables to CSS file in Django

查看:48
本文介绍了将变量传递给Django中的CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在CSS文件中传递变量,例如在HTML文件中传递变量.示例:

Is it possible to pass variables in CSS files, like in HTML file. Example:

在views.py中:

In views.py:

def home(request):
    bgcolor = "#999"
    ...
    ...

在CSS文件中:

body {
    background-color : {{bgcolor}};
}

如果是,请您指导我如何实现这一目标?我真的很感激.谢谢!

If yes, can you please guide me how to achieve this? I would really appreciate. Thank you!

好的,我不好.我的意思是,用户如何根据需要自定义页面?我想我可以不用外部样式表就可以做到这一点,但是我认为CSS是最快的,如果它是静态的并且在CDN上并且不使用模板和CPU资源进行渲染.如果有办法实现这一目标,请指导我.

Ok, my bad. What I meant was, how do let users customize their page if they wanted to? I suppose I could have done this without using external stylesheet, but I think CSS is served fastest if it's static and on a CDN and not using a template and CPU resources to render. Please guide me if there's a way to achive this.

推荐答案

那不是做这种事情的方法.您应该在CSS文件中定义不同的类,然后根据模板中的变量在模板中使用then.

That's not the way to do this sort of thing. You should define different classes in the CSS file, then use then in your template dependent on the variables there.

这篇关于将变量传递给Django中的CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆