Skip to content Skip to sidebar Skip to footer

Set A Variable In Django Template File, And Update It After Iteration

Trying to set variable in django template, and make a simple rule to update it after iteration. Here is my template: {% for adv in advs %}

Create a templatetags directory in your app. Add an empty __init__.py and multiply_add.py.

multiply_add.py

from django import template
register = template.Library()

@register.simple_tagdefmul_add(a, b, base_value):
    return (a * b) + base_value

template.html

{% load multiply_add %}

{% for adv in advs %}
<divclass="media-item big"style="top: 18%;left:{% multiply_add forloop.counter0 774 304 %}px;"><divclass="media-item__tags"><ahref="#"class="tag">{{ adv.year }}</a><ahref="#"class="tag">{{ adv.payer}}</a></div><divclass="media-item__content"><divclass="media-item__background"><ahref="project-spar.html"class="media-item-background__link"></a><divclass="media-item__canvas"><divclass="media-item__canvas-background"style="background-image: url({{adv.image.url}})"></div></div><h2class="topic white upcase fixed-size">{{ adv.name }}</h2><ahref="#"class="link regular width600-only">Смотреть проект</a></div></div></div>

Post a Comment for "Set A Variable In Django Template File, And Update It After Iteration"