Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
For this, you can add middleware.py with similar content
# -*- coding: UTF-8 -*-
from django.conf import settings
class NewStyleTemplateDir(object):
@staticmethod
def process_request(request):
if request.GET.get('new_style'):
settings.TEMPLATES[0]['DIRS'] = ['новая директория с шаблонами']
maybe something like this?
import settings
if 'new_style' in request.GET:
style = request.GET.get('new_style')
делаем что-то с settings.TEMPLATE_DIRS ( = style directory)
When using cbv descendants of TemplateResponseMixin, the get_template_names method is responsible for this.
You can set TEMPLATES['DIRS'] to both folders: old and new, give new templates slightly different names (with _ at the beginning for example) and place them in the new folder. And then write:
class MyView(TemlateView):
def get_template_names(self):
style = self.request.GET.get('new_style', 0)
if style == 1:
return list(map(lambda t: '_{}'.format(t), super().get_template_names())
return super().get_template_names()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question