Django 1.8 with Jinja2: Contrib app Admin not working

怎甘沉沦 提交于 2019-12-05 07:24:43

The admin app does not come with Jinja2 templates. You need to configure your project to use Django and Jinja2 templates.

The Django template docs has the following example.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            '/home/html/example.com',
            '/home/html/default',
        ],
    },
    {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'DIRS': [
            '/home/html/jinja2',
        ],
    },
]

The ideal solution would be to make the default template system take precedence over the Jinja system. The only difference is the DIRS specified need to be different. If you are only concerned about the admin, the process is fairly easy.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [], # This is particularly important as it will not look into the default template directory
    },
    {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
    },
]

Just remember that the directory structure must not allow the default template system to access your main pages.

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