Is it possible to pass variables in CSS files, like in HTML file. Example:
In views.py:
def home(request):
bgcolor = "#999"
...
...
In the CSS file:
body {
background-color : {{bgcolor}};
}
If yes, can you please guide me how to achieve this? I would really appreciate. Thank you!
Edit: 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.
This is a old question but I thought I'd help others as I also wanted to do this and I found a solution.
Instead of using a normal link tag specifying your stylesheet, use style tags and include your css file inline.
<style>{% include 'my.css' %}</style>
Then you can put jinja code in your css file and it will render the variables. Useful if you want to allow users to customize colors etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With