[Django]-Django template variable in style tag

2👍

Instead of include tag which trying to find template named percent_style you should simple use {{ percent_style }}:

{% with "width: "|add:percent|add:"%" as percent_style %}
<div class="percentile" style="{{ percent_style }}" />
{% endwith %}

2👍

It seems to be easy to do, instead of trying to include, just use the variable concatenated with the percent % sign. You don’t need to use {% with %} {% endwith %}

<div class="percentile" style="width:{{ percent }}%" />

Leave a comment