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.

Llanilek
  • 3,386
  • 5
  • 39
  • 65
  • your server django version is right? and server template directory is right? – skymoney Apr 15 '15 at 14:22
  • 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. – Llanilek Apr 15 '15 at 14:23
  • 1
    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). – Alasdair Apr 15 '15 at 15:14
  • Check, that os.path.join(BASE_DIR, 'templates') point to the same directory, where you template is located. – Sergey Lyapustin Apr 16 '15 at 11:04
  • Than submit that as the answer and mark the question as answered. – Rebs May 17 '15 at 04:29

1 Answers1

2

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

Doing this, fixed the issue.

Llanilek
  • 3,386
  • 5
  • 39
  • 65