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_tag
def mul_add(a, b, base_value):
    return (a * b) + base_value

template.html

{% load multiply_add %}

{% for adv in advs %}
<div class="media-item big" style="top: 18%;left:{% multiply_add forloop.counter0 774 304 %}px;">
    <div class="media-item__tags">
         <a href="#" class="tag">{{ adv.year }}</a>
         <a href="#" class="tag">{{ adv.payer}}</a>
    </div>
    <div class="media-item__content">
        <div class="media-item__background">
            <a href="project-spar.html" class="media-item-background__link"></a>
            <div class="media-item__canvas">
                <div class="media-item__canvas-background" style="background-image: url({{adv.image.url}})"></div>
            </div>
            <h2 class="topic white upcase fixed-size">{{ adv.name }}</h2>
            <a href="#" 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"