After installing jinja2 TemplateDoesNotExist at /admin/

狂风中的少年 提交于 2019-12-12 17:01:19

问题


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

templates look like that:

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',
        ],
    },
},
]

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

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


回答1:


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.
    },

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.



来源:https://stackoverflow.com/questions/44890665/after-installing-jinja2-templatedoesnotexist-at-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!