[Django]-TemplateSyntaxError: Could not parse the remainder

6👍

You seem to be confused between Jinja2 syntax and the Django template syntax. Jinja2 is a separate project, inspired by Django, but not used by Django itself.

In the Django template syntax, variables in {{...}} always use dot notation, [...] subscriptions are not supported. Out of the box, the language does not support dictionary key lookups.

You can write a custom filter to achieve this, like the following, written by culebrón:

from django.template.defaulttags import register

@register.filter
def get_item(dictionary, key):
    return dictionary.get(key)

then in the template:

{{ img_gallery|get_item:item.id|first }}

Alternatively, you could switch to using Jinja2 in your Django project, replacing the built-in template language: How to use jinja2 as a templating engine in Django 1.8

Leave a comment