Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using TEMPLATE_STRING_IF_INVALID with Django 1.8

Tags:

django

I'm getting following warning when using Django 1.8:

?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_STRING_IF_INVALID.

I'm using settings from Django 1.7. Where should the TEMPLATE_STRING_IF_INVALID go exactly in Django 1.8?

like image 340
SaeX Avatar asked Dec 01 '25 03:12

SaeX


1 Answers

Remove TEMPLATE_STRING_IF_INVALID = 'Invalid: %s' or similar from the settings and add string_if_invalid to the options of the new TEMPLATES setting:

DEBUG = False
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
            ],
            'debug': DEBUG,
            'string_if_invalid': 'Invalid: "%s"'
        },
    },
]

Alternatively if you're using a production and a development settings file, add following statement to the development settings file:

DEBUG = True
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
TEMPLATES[0]['OPTIONS']['context_processors'].append('django.template.context_processors.debug')
TEMPLATES[0]['OPTIONS']['string_if_invalid'] = 'Invalid: "%s"'
like image 187
SaeX Avatar answered Dec 03 '25 01:12

SaeX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!