Django 1.8 not using Jinja2 template engine
NickName:ratata Ask DateTime:2015-09-11T18:23:35

Django 1.8 not using Jinja2 template engine

I have followed the instructions on using jinja2 with django1.8. --->

#settings.py

TEMPLATES = [
    {

        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'DIRS': [
            normpath(join(DJANGO_ROOT, 'templates/jinja2')),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'environment': 'kuyuweb_dj_1_8.jinja2.environment',
        },
    },
    {

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                'django.core.context_processors.request',
            ],
        },
    },
]

I have a .py file including environment -->

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

and in my application folder i have templates/jinja2 folder. I have created a simple view as:

def home(request):

    works = Work.objects.filter(publish=True).order_by('-created_at')[:8]

    return render(request, 'jinja2/home.html', {'works':works })

But for example when i try to use jinja2 template tag as {{ loop.index }} it does not work. {{ forloop.counter }} is still working.

Is there something that i miss?

Copyright Notice:Content Author:「ratata」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32521189/django-1-8-not-using-jinja2-template-engine

More about “Django 1.8 not using Jinja2 template engine” related questions

Django 1.8 not using Jinja2 template engine

I have followed the instructions on using jinja2 with django1.8. ---> #settings.py TEMPLATES = [ { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [

Show Detail

How to use jinja2 as a templating engine in Django 1.8

I have been looking on how to use jinja2 in django 1.8, but there is no complete source for using django with jinja2. I was wondering if you guys knew the process for using jinja2 in django. I have

Show Detail

Django 1.8 with Jinja2: Contrib app Admin not working

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 templat...

Show Detail

Django: Can't find templates when using Jinja2 as engine

I'm using Django 1.8, which allows you to switchout the Django Template Engine for Jinja2. I have the following in my setting.py TEMPLATES = [{ 'BACKEND': 'django.template.backends.jinja2.Jin...

Show Detail

Django jinja2 template, extends another template. Django renders base template without jinja2

I'm using jinja2 to render a template in django: TEMPLATES = [ { "BACKEND": "django.template.backends.jinja2.Jinja2", "DIRS": [os.path.join(BASE_DIR, "templates/jinja2/"

Show Detail

Using django-widget-tweaks with Jinja2 template engine

I'm using django v1.11.7 with Jinja2 v2.10 as the template engine. In my website, I wish to render forms using bootstrap. I found out that django-widget-tweaks can be used for this integration. ...

Show Detail

Django can't find templates with jinja2 engine

I'm going to change django's template engines to jinja2, but after setting the setting.py of my project, jinja2 engines doesn't work, the followings are my codes. settings.py TEMPLATES = [ ...

Show Detail

Is there a simple way to use django's template engine for django's own views and jinja2 engine for my own views?

For convenience, I use a custom Jinja2 template loader for all views of my Django project with this method. Thus No matter where I write my own view funcitons, I don't have to write or declare anyt...

Show Detail

Rendering django forms with jinja2 template engine

I am using jinja2 template engine in django project. I made corresponding changes in settings: TEMPLATES = [ { 'BACKEND': 'django.template.backends.jinja2.Jinja2', 'DIRS': [os....

Show Detail

Where do I put jinja2 helpers in a django 1.8 project?

I'm currently upgrading django from 1.7.10 with jingo to 1.8.5 (actually from 1.6.x but I can now run the site with 1.7) jingo no longer works with django 1.8 so I'm switching to the new Jinja2 su...

Show Detail