当我拥有看似正确的设置时,出现 Invalid BACKEND 错误--为什么?

4
在Ubuntu 14.04上的Django开发服务器上运行Django 1.8。我遇到了这个错误:
Invalid BACKEND for a template engine: <not defined>. Check your TEMPLATES setting.

我的设置文件包含:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    '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',
        ],
    },
},
]

当我执行 `python manage.py diffsettings` 命令时,会得到以下输出:

...
TEMPLATES = [{'DIRS': [], 'APP_DIRS': True, 'BACKEND':    'django.template.backends.django.DjangoTemplates',
 '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']}},
 {'TEMPLATE_DEBUG': 'DEBUG'}]

而且当我通过django.conf导入它时,可以在shell中使用它。这是怎么回事?

更新:

值得注意的是,我正在运行Python3。


你重启了服务器吗? - levi
@levi,说得好。但是确实会得到相同的结果。TEMPLATES包含在调试页面列出的变量中。 - David Boshton
1
那很奇怪。你的配置是正确的。你确定文件中没有其他的配置吗?你确定你的虚拟环境是激活的吗? - Nostalg.io
你有旧的 settings.pyc 文件还留在哪里吗? - Ben
1个回答

0

哦,亲爱的。似乎是在结尾多了一个标签元素,列表中的{TEMPLATE_DEBUG: DEBUG}元素。将其删除后,现在已经通过了该点。

实际上,这是以前的做法。1.8的方法是将debug: True作为字典中的关键词。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接