在/admin/下安装jinja2 TemplateDoesNotExist之后

编程入门 行业动态 更新时间:2024-10-16 22:17:16
本文介绍了在/admin/下安装jinja2 TemplateDoesNotExist之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经安装了jinja2,然后"DIRS"停止工作(我必须手动添加它们). 更改"APP_DIRS"无济于事

I have installed jinja2 and after that 'DIRS' stopped working(I have to include them by hand). Changing 'APP_DIRS' doesn`t help

模板看起来像这样:

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中,则会引发相同的错误

If don`t include templates into DIRS it throws the same error

找不到这样的问题.预先感谢!

Didn`t find the questions like that. Thanks in advance!

推荐答案

Django管理应用程序不附带Jinja模板.如果要使用Jinja和管理应用程序,则需要在TEMPLATES设置中包括两个引擎:

The Django admin app does not come with Jinja templates. If you wish to use Jinja and the admin app, you need to include both engines in your TEMPLATES setting:

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

第二,当APP_DIRS为True时,Jinja2后端在jinja2子目录中查找模板.这意味着您应该将模板放在main/jinja2和shop/jinja2中,而不要放在main/templates和shop/templates中.

Secondly, when APP_DIRS is True, the Jinja2 backend looks for templates in a jinja2 subdirectory. That means you should put your templates in main/jinja2 and shop/jinja2 instead of main/templates and shop/templates.

更多推荐

在/admin/下安装jinja2 TemplateDoesNotExist之后

本文发布于:2023-10-09 05:45:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:admin   TemplateDoesNotExist

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!