R
R
raiboon2014-12-26 12:43:29
Django
raiboon, 2014-12-26 12:43:29

How to make Django templates not swallow errors?

The settings are TEMPLATE_DEBUG.
But I found that it throws an exception in one method, and the templates swallow it - it debugged for a long time until I called it in the code.
Well, in general, so that he would not hush up None values.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2014-12-26
@MAKAPOH

As far as I remember, the TEMPLATE_STRING_IF_INVALID setting is responsible for this . Define it as '%s'

D
Dmitry Kirichuk, 2015-01-04
@orgkhnargh

# settings.py
class InvalidVarException(object):
    def __mod__(self, missing):
        try:
            missing_str=unicode(missing)
        except:
            missing_str='Failed to create string representation'
        raise Exception('Unknown template variable %r %s' % (missing, missing_str))
    def __contains__(self, search):
        if search=='%s':
            return True
        return False

TEMPLATE_DEBUG=True
TEMPLATE_STRING_IF_INVALID = InvalidVarException()

Will throw an exception if some variable in the template is not initialized.
Source: stackoverflow.com/a/15312316/4227594

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question