In a template I'd like evaluate this expression
assoc = service not in backends.not_associated
And store it in a variable, here is the context:
<ul class="list-inline">
{% for service in backends.backends %}
{% with assoc=service not in backends.not_associated %}
<li{% if assoc %} class="associated"{% endif %}>
<a rel="nofollow"
href="{% url
'social:'|add:assoc|yesno:'begin,disconnect' service %}"
title="{{ service|title }}">
<img src="{% static 'social_icons/'|add:service|add:'.png' %}" />
</a>
</li>
{% endwith %}
{% endfor %}
</ul>
With am I getting this error ?
u'with' received an invalid token: u'not'
It seems with
can't evaluate a boolean operation, can it ?
{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
8. What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.
{% include %} Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.
You cannot use python code in django template. This is by design, Django's idea of template is to isolate the presentation logic from the programming code. Save this answer.
You can't evaluate expressions in django templates. To do so, you must use custom template tags. You could use assignment tag for your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With