how to dynamically load css names into django templates without cluttering the view -


i have django app , retrieve there "theme" value memcached in views.py , pass several templates. i've achieved able switch jqueryui theme of various templates system-wide.

here example of template:

  <link rel="stylesheet" href="{% static "jquery-ui-1.11.4/themes/"%}{{theme}}/jquery-ui.css"> 

the problem need retrieve , pass theme various view end points , if forget 1 of them, pf course theme not found. there better way? maybe using template tags?

usecontext processor

in app/mycontexts.py

def mytheme(request):         return {             'theme':"themename",         } 

then in settings.py

template_context_processors = (     #your contxt processors     "path.to.app.mycontexts.mytheme",  ) 

for django >= 1.7

templates = [     {         'backend': 'django.template.backends.django.djangotemplates',         'dirs': [],         'app_dirs': true,         'options': {             'context_processors': [                 #your contxt processors                 "path.to.app.mycontexts.mytheme",              ],         },     }, ] 

then {{theme}} in every view.no need pass in every every view.


Comments