views:

117

answers:

1

I'm wondering if there is anything like Django's HTML templating system, for for CSS.. my searches on this aren't turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I can tell, these still don't solve my issue as I want to dynamically generate a CSS file based on certain conditions, so that a different CSS file would be served based on a specific user session...

I want to minimize the use of javascript / AJAX for some things (since its for a legacy system running in some hospital where they're still using IE 6 ), also I have an interest in possibly minimizing javascript for other projects as well... so it would be where there is 1 CSS file, but that it may need to be changed based on the situation (which would be done with CleverCSS), however the problem is that if I just write the changes to 1 file, then this would be served to everyone, even though they may have a different "state" of the CSS file depending on their use of the application, so I want to remove the physical association of a CSS file and rather have it dynamically generated each time (so that its unique to a specific user's session), the way that Django's HTML templating system works..

+4  A: 

The Django templating system can be used for any text you like. It's used for HTML most of the time, but it could also be used to create CSS. The CSS reference in your HTML can be to a dynamic URL instead of to a static file, and the view function can create whatever context you like, then a .css template file can create your CSS.

If you have only a few different CSS possibilities, then you may be better served by creating them as static files, and using the HTML template to select the CSS file you want by writing a different CSS reference depending you your conditions.

Ned Batchelder
Thanks, didn't realize that as I'm new to Django, what you said makes perfect since, I will try it that way
Rick