2017-07-03 30 views
0

处安装jinja2 TemplateDoesNotExist后,我安装了jinja2,然后'DIRS'停止工作(我必须手动包含它们)。 更改“APP_DIRS”不`吨帮助在/ admin/

模板看起来像:

TEMPLATES = [ 
{ 
    'BACKEND': 'django.template.backends.jinja2.Jinja2', 
    'APP_DIRS': False, 
    'DIRS': ['main/templates', 'shop/templates'], 
    'OPTIONS': { 
     'environment': 'django_test.create_jinjia_env.environment', 
     'autoescape': True, 
     'auto_reload': DEBUG, 
     'context_processors': [ 
      'django.template.context_processors.debug', 
      'django.template.context_processors.request', 
      'django.contrib.auth.context_processors.auth', 
      'django.contrib.messages.context_processors.messages', 
     ], 
    }, 
}, 
] 

如果不`吨包括模板到DIRS它抛出了同样的错误

Didn`t喜欢找问题。提前致谢!

回答

2

Django管理员应用程序不带有Jinja模板。如果您想使用神社和管理应用程序,你需要包括两个引擎在TEMPLATES设置:

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, # This allows Django to find the templates in the admin app 
     ... 
    }, 
    { 
     'BACKEND': 'django.template.backends.jinja2.Jinja2', 
     # The rest of your Jinja2 settings. 
    }, 

其次,当APP_DIRS为True,后端的Jinja2 looks for templates in a jinja2 subdirectory。这意味着你应该把你的模板放在main/jinja2shop/jinja2而不是main/templatesshop/templates

+0

非常感谢帮助和简洁! – Michael

相关问题