I upgraded to a fresh install of Django 1.8 and began using Jinja2 as it said that it was supported now and Jinja2 has some features I could use in my project.
After finishing adapting the templates for my app to Jinja2 and taking advantage of the new features now available, I discovered that the contrib app Admin no longer works.
"TemplateDoesNotExist at /admin/login/"
So it turns out that contrib app Admin only has templates made for DjangoTemplates and not for Jinja2. I did the naive thing first and made a symlink in [...]/site-packages/django/contrib/admin
from templates
to jinja2
but the templates were using DjangoTemplates specifics and so Jinja2 would not accept them. I removed the symlink.
The way I have switched over to Jinja2 is by making the following change in my project settings.py
:
TEMPLATES = [
{
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [],
'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',
- ],
- },
},
]
Does anyone know of either:
Thank you for your time :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With