A
A
Andrew2014-03-12 11:31:23
Django
Andrew, 2014-03-12 11:31:23

How to pass parameter received from view to css?

Good afternoon!
When a list of parameters is passed to the template, the value of one of the parameters must be passed as the width of the element. I am using django1.5 and bootstrap2.3.
For example, there is such a block:

<div class="progress">
        <div class="bar bar-success" style="width: 20%;"></div>
        <div class="bar bar-danger" style="width: 80%;"></div>
    </div>

You need to do something like this:
<div class="progress">
        <div class="bar bar-success" style="width: {{ value }}%;"></div>
        <div class="bar bar-danger" style="width: 100-{{ value }}%;"></div>
    </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jettary, 2014-03-12
@aphex

Django template supports the add filter , however it doesn't work for the variant style="width: {{ 100|add:-value }}%;".
Therefore, you can write your own filter :

@register.filter    
def subtract(value, arg):
    return value - arg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question