I want to add a functionality which let the user choose a "interface theme':
I added a dropdown in my base.html so the user can change the theme in all the templates.
I use a base.html for all my html templates using {% extends 'base.html'%}.
'# All my views will need this:
theme = MyThemeModel.objects.filter(user=self.request.user).first().theme
return render(request, 'mytemplate.html', {'theme': theme})
'#base.html
{% if theme = 'theme 1'%}
<link rel="stylesheet" type="text/css" href="{% static 'theme1.css' %}" />
{% else if theme = 'theme 2'%}
<link rel="stylesheet" type="text/css" href="{% static 'theme2.css' %}" />
{% else if theme = 'theme 3'%}
<link rel="stylesheet" type="text/css" href="{% static 'theme3.css' %}" />
{% endif%}
I'm thinking of using AJAX so I can take the theme the user choose but then I will need to add a function in each existing view and I don't want to repeat that much of code.
Is there an easier way to do this?