简体   繁体   中英

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.

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

Doing this, fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM