I have a context dictionary containing data to be passed into the template. I need to toggle two divs based on some flag variable which I have implemented using {% with %}
Django template tag. However, when I try to set the variable using {% set %}
syntax I am getting following error:-
set', expected 'endwith'. Did you forget to register or load this tag?
I following the solution given here but it gives me error.
index.html
{% with flag=1 %}
{% for benefit in content.benefits %}
<div style="background-color: #fff;" class="row mt-5">
{% if not flag %}
<div class="col-lg-4 col-md-4 col-sm-12">
<img src="{% static "{{benefit.image}}" %}" alt="tablet"
class="img-responsive mx-auto mt-5 w-100 h-75 h-md-50 working-img">
</div>
{% endif %}
<div class="col-lg-8 col-md-8 col-sm-12 h-100">
{% for desc in benefit.heading %}
<div class="d-flex h-25 w-100 m-1 mt-4">
<div class="col-3 col-sm-2 h-100">
<div class="mx-auto">
<i class="fas fa-check fa-2x" style="color: #6fe33d"></i>
</div>
</div>
<div class="col-9 col-sm-10">
<div class="d-flex flex-column">
<div class="working-caption font-weight-bold">{{ desc }}</div>
{# <div class="py-2 working-description-courses text-muted">{{ description }}</div>#}
</div>
</div>
</div>
{% endfor %}
</div>
{% if flag %}
<div class="col-lg-4 col-md-4 col-sm-12">
<img src="{% static "{{benefit.image}}" %}" alt="tablet"
class="img-responsive mx-auto mt-5 w-100 h-75 h-md-50 working-img">
</div>
{% endif %}
</div>
{% endfor %}
{% set flag=1-flag %}
{% endwith %}
settings.py
...
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'environment': 'myapp.jinja2.environment'
},
},
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
...