Updating Django template settings from 1.7 to 1.8
Asked Answered
S

1

6

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.

Salter answered 15/4, 2015 at 14:17 Comment(5)
your server django version is right? and server template directory is right?Livingstone
Server is running django 1.8 the exact same version as my local. The directory is the same also as it's a repository that I upload to directly.Salter
Do you have a full traceback? It might list the templates template that it failed to find, and the directories that it searched. Secondly, you haven't set APP_DIRS: True in your settings. That might cause problems if you use any app that comes with templates (e.g. the admin).Suffocate
Check, that os.path.join(BASE_DIR, 'templates') point to the same directory, where you template is located.Tulatulip
Than submit that as the answer and mark the question as answered.Sharlenesharline
S
2

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

Doing this, fixed the issue.

Salter answered 7/7, 2015 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.