LauraBen
LauraBen

Reputation: 119

error while converting Django template engine to jinja2, unable to use 'with'

I have converted a small Django project to use jinja2 as a backebd engine. Now in one of the templates I am writing the following code:

{% include 'base/rating.html' with rating=location.get_average_rating() %}

The code above works fine with the Django template but when I switch the template engine to Jijna2 I am getting the following error.

Request Method: GET Request URL: http://127.0.0.1:8000/location/ Django Version: 1.10.5 Exception Type: TemplateSyntaxError Exception Value:
("expected token 'end of statement block', got 'with'",) ]

and the browser shows the following error

Really want to know how I need to change such code for it to work in jinja2. tried multiple things from jinja documentation about #with-statement but nothing worked. Thanks in advance.

Upvotes: 1

Views: 364

Answers (1)

Alasdair
Alasdair

Reputation: 308999

You can use the with statement.

{% with rating=location.get_average_rating() %}
    {% include 'base/rating.html' %}
{% endwith %}

Upvotes: 1

Related Questions