Django: can't find patterns when using Jinja2 as an engine

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 # Python 2 only from django.contrib.staticfiles.storage import staticfiles_storage from django.core.urlresolvers import reverse from jinja2 import Environment def environment(**options): env = Environment(**options) env.globals.update({ 'static': staticfiles_storage.url, 'url': reverse, }) return env 

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.

+4
source share