Having written a lot of python before I'm quite new to django, and loving it so far.
My previous web experience is in PHP and in order to make my CSS easy to maintain I use a php file as my CSS and serve it as CSS content-type. Therefore I can make variables which can easily be changed to make everything in the site change.
e.g. styles.php:
<?php header('Content-type: text/css');
$pink = '#91305f';
$green = '#a4ce39';
$black = '#000000';
$white = '#ffffff';
$std_font = "'Ruda', sans-serif";
$std_shadow = "text-shadow: 1px 1px 1px #000;";
$big_shadow = "text-shadow: 2px 2px 2px #000;";
$h_space = '10px';
?>
and...
html {
background-color:<?= $pink ?>;
color: <?= $green ?>;
font-family: <?= $std_font ?>;
}
so if I want to change what black means in my whole site, I just alter the $black = at the top and all places in my CSS where I've said color: ; will follow.
I want to achieve the same type of thing in django but can't figure out how to do it. I'm thinking I could use a view to render a template in css but not really sure how to go about this. Is it as simple as creating a dict in my view and passing it to render_to_response then referring to it in my template file?
e.g. views.py:
def style(request):
colours = {'pink' : '#91305f', 'green' : '#a4ce39'}
return render_to_response('styles.css', {'styles': colours},
context_instance=RequestContext(request))
then, in templates/styles.css:
html {
background-color:{{ styles.pink }};
color: {{ styles.green }};
}
Is this a viable solution? If so, it seems like I am coupling the view to the template but I can't figure out where I would otherwise store the data needed to achieve this.
Thanks Aaron