(admin.E403) A ‘django.template.backends.django.DjangoTemplates’ instance must be configured in TEMPLATES in order to use the admin application.| 使用jinjia2時報錯
1 問題分析
(admin.E403) A ‘django.template.backends.django.DjangoTemplates’ instance must be configured in TEMPLATES in order to use the admin application.
解讀:(admin.E403)必須在TEMPLATES中配置'django.template.backends.django.DjangoTemplates'實例,才能使用管理應用程序。
言下之意就是您的需要在您django項目下的setting中TEMPLATES增加django模板引擎。
2 解決(linux系統下)
2.1 修改django項目下setting中的TEMPLATES
筆者本機地址為(您可以參考這來尋找):
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'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',
],
'environment':'app.base_jinja2.environment' # 具體路徑按照您實際的來
},
},
{
'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',
],
},
}
]
注意
一定要把jinja2 引擎放在前面, 否則默認生效的還是django模板引擎.