0

I am following this thread here... How to use jinja2 as a templating engine in Django 1.8

I can't seem to find any solid docs on switching to jinja2 templates and how to setup django for it. All the docs seem to have some gaps, or I am missing somehting really obvious. Anyway, I set everything up just like the thread above, except when I try to go somewhere where the template would be loaded I get...

TemplateDoesNotExist

Django tried loading these templates, in this order:
    ...

But it does not list any of my jinja/ template directories that I specified. Why would this be?

EDIT ADDING TRACE AND SETTINGS:

TEMPLATES = (
    {
        'BACKEND': 'askbot.skins.template_backends.AskbotSkinTemplates',
    },
    {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'DIRS': [os.path.join(PROJECT_ROOT, 'templates/jinja2')],
        'APP_DIRS': True,
        'OPTIONS': {'environment': 'myproject.jinja-import.Environment',}, 
    },
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PROJECT_ROOT, 'templates',),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.core.context_processors.request',
                'django.contrib.auth.context_processors.auth',
            ]
        }
    },
)

Traceback:
File "/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jeff/Django/langalang-askbot/langalang/main/views.py" in page
  71.       context_instance=RequestContext(request, context))
File "/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/shortcuts.py" in render
  89.             using=using)
File "/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/template/loader.py" in render_to_string
  137.             raise TemplateDoesNotExist(template_name)

Exception Type: TemplateDoesNotExist at /ko/
Exception Value: main/page.html

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/jeff/Django/langalang-askbot/langalang/templates/main/page.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/contrib/auth/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/contrib/admin/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/Django-1.8.8-py2.7.egg/django/contrib/sitemaps/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_compressor-1.5-py2.7.egg/compressor/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/langalang/askbot-dev/askbot/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_robots-1.1-py2.7.egg/robots/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_celery-3.1.17-py2.7.egg/djcelery/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_tinymce-1.5.3-py2.7.egg/tinymce/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_recaptcha-1.0.5-py2.7.egg/captcha/templates/main/page.html (File does not exist)
/home/jeff/Django/langalang-askbot/venv/local/lib/python2.7/site-packages/django_avatar-2.2.1-py2.7.egg/avatar/templates/main/page.html (File does not exist)

view that is loading the template:

def page(request, page_title='home'):


    context = {
        'page_title': page_title
    }

    if page_title == 'home':
        #This query pulls the language instructions objects and then orders it alphabetically by the 'full_title' field
        language_pairs = LangPairInstruction.objects.filter(active=True).order_by('full_title')
        context['language_pairs'] = language_pairs

    elif page_title == 'contact':
        form_class = ContactForm(initial={'subject': _('Subject'), 'name': _('Name'), 'email': _('Email'), 'content': _('Content')})
        context['ContactForm'] = form_class

    elif page_title == 'about':
        pass

    else:
        raise Http404

    return render(
        request, 
        'main/page.html', 
        context_instance=RequestContext(request, context))
Community
  • 1
  • 1
Joff
  • 11,247
  • 16
  • 60
  • 103
  • Where is the `main/page.html` template that Django is not finding? – Alasdair Jan 27 '16 at 16:05
  • templates/jinja2/main/page.html – Joff Jan 27 '16 at 16:07
  • 1
    What is `PROJECT_URL`? What does Django list underneath "Django tried loading these templates, in this order:"? – Alasdair Jan 27 '16 at 16:11
  • PROJECT_ROOT is the directory that contains the settings file, added the directories django tried to load to the main post – Joff Jan 27 '16 at 16:15
  • @Alasdair added the view – Joff Jan 27 '16 at 16:17
  • The `templates/jinja2` directory is definitely in the same directory as your `settings.py`? I'm surprised that the jinja2 loaders are not mentioned in the error message. Are you definitely editing the correct settings.py, and have you restarted your server after changing the settings? – Alasdair Jan 27 '16 at 16:21
  • I'm not familiar with askbot, so I don't know whether the `AskbotSkinTemplates` loader could cause problems. – Alasdair Jan 27 '16 at 16:22
  • @Alasdair yes to everything you said – Joff Jan 27 '16 at 16:24

0 Answers0