Django 1.8 で、TEMPLATE_DEBUG 、TEMPLATE_DIRS が非推奨になった

Django 1.8 で、TEMPLATE_DEBUG 、TEMPLATE_DIRS が非推奨になりました。
1.8 以前の settings.py を引き継いで、

TEMPLATE_DEBUG = True

と記載していました。

python3 manage.py check

を実行すると、警告が出てきて、

?: (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_DEBUG.

もう廃止されたと言われます。


修正方法

じゃあ、どう書くのかというと、以下 サイトにわかりやすく書いてありました。

TEMPLATE_DEBUG deprecated — Python Anti-Patterns documentation

TEMPLATESのOPTIONSに'debug': True,指定すると、
同じ意味になるようです。

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,  'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            'debug': True, #コレを指定する
        },
    },
]

以上です。

コメント