I am using Django 1.8, which allows you to switch the Django Template Engine for Jinja2.
I have the following in my .py setup
TEMPLATES = [{ 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [ os.path.join(BASE_DIR, 'templates/jinja2'), ], 'APP_DIRS': True, 'OPTIONS': { 'environment': 'appname.jinja2.environment', }, },]
I mainly use the instructions http://jonathanchu.is/posts/upgrading-jinja2-templates-django-18-with-admin/ , except that I am trying to get the engine to find patterns in patterns in each additional application. So,
βββ myproject β βββ __init__.py β βββ jinja2.py β βββ settings.py β βββ urls.py β βββ wsgi.py βββ app2 β βββ __init__.py β βββ other app stuff ... βββ templates β βββ jinja2 β βββ app2 β βββ template.html βββ manage.py βββ templates β βββ jinja2 β βββ something.html
Both applications are installed:
INSTALLED_APPS = ( ... 'myproject', 'app2', )
myproject / jinja2.py contains:
from __future__ import absolute_import
but still, I get an Exception Type: TemplateDoesNotExist when I use
from django.template.loader import get_template template = get_template('app2/template.html')
I tried adding add
TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', )
tried to add {'loader': Loader} to βOPTIONSβ, where Loader is from django.template.loaders.app_directories import Loader , and also use some Jinja2 loaders. No one worked.
If I add the DjangoTemplates mechanism as secondary, it will find the template. Jinja2 does not do this. Previously, the Debug Traceback screen showed that only django.template.loaders.filesystem.Loader (bottom right, where it says "Traceback Switch to copy-and-paste view"), but now it doesn't tell me anything.
I use Windows and the development server ( manage.py runserver ). I do not have TEMPLATE_DIRS parameters in settings.py (although hardcoding the specific application template directory in TEMPLATE_DIRS also does not fix the problem; in fact, I got the warning The standalone TEMPLATE_* settings were deprecated in Django 1.8..., When I delete this, I do not get the problem (0 disabled))
I do not get one of the following in my track:
Template Loader Error: Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader:
Looked:
Django can't find dir pattern?
Django cannot find a template
Django cannot find application templates
I have no ideas. Reference.