Enable django TEMPLATE_STRING_IF_INVALID with one method

I created a view that displays a preview of other templates. I want to show empty tags inside templates, so I included

TEMPLATE_STRING_IF_INVALID = '%s'

... in my file settings.py. However, I would like to enable this option for a specific view, but not globally in my application.

Thanks in advance.:)

+5
source share
1 answer
from django.conf import settings

def myview(request):
    settings.TEMPLATE_STRING_IF_INVALID = '%s' # '%s' will get expanded to the variable name that was not found
    ...
    template = render(request, 'myview.html', {})
    settings.TEMPLATE_STRING_IF_INVALID = ''
    return template

, . , reset TEMPLATE_STRING_IF_INVALID '', . Django docs , open , , .

, - .

+1

All Articles