Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Template tags in javascript and css files

Is there any way to add template tags into javascript and css files? I would use it for anything from passing in urls to media url links (image paths, etc) to conditional javascript based on user permissions.

I just had a thought that maybe I can serve it up as if it were a template but have the url as my javascript file. Is that the only way to do somethign like this? If so, it probably wouldn't work with my media generator, so I'd probably want a better solution if there was one out there.

like image 857
killerbarney Avatar asked Aug 23 '10 18:08

killerbarney


1 Answers

How about defining the JavaScript variables and CSS attributes from within your Django HTML template, between script and style tags? I know it sounds like a hack, but it seems to me a tidy one, as this will allow you to control your dynamic variables from one spot.

like image 191
dmvianna Avatar answered Sep 22 '22 22:09

dmvianna