Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Django template settings from 1.7 to 1.8

So I've been tinkering with upgrading to the new version of Django (1.8). I'm currently on version 1.7 and I am struggling to get my production server to listen to the new settings in 1.8.

As of 1.8, any TEMPLATE_* settings have been deprecated according to the documentation and has been replaced with the TEMPLATES setting.

I'm trying to just continue as I was, but I wish to move to the new settings before the deprecation timeline ends.

In my 1.7 settings I have only got two of the old settings which are now deprecated as follows:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += ("django.core.context_processors.request",)

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

In the new 1.8 settings I've got the following:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
                # list if you haven't customized them:
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.request',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

However when I use these settings, my production server cannot locate the template files, yet my local works just fine.

EDIT: Turns out APP_DIRS setting being missing was playing havoc with openshift. I have all my templates in one directory, not in application dirs, but this seemed to resolve the issue.

like image 399
Llanilek Avatar asked Apr 15 '15 14:04

Llanilek


1 Answers

It seems that openshift doesn't read the DIRS: setting unless APP_DIRS: is set as True

Doing this, fixed the issue.

like image 150
Llanilek Avatar answered Sep 22 '22 10:09

Llanilek