0

I have some django application, i need to render some html with this block of code:

{% for i in review.mark|range %}
     img src="{% static 'core/img/star-yellow.svg' %}" alt="star">
{% endfor %}

Sometimes filter range help me with this (review.mark is only IntegerField in my model). I have mark from 1 to 5, and i want to loop for review.mark times. How can i do this in django templates?

0

1 Answer 1

0

we can do like below

{% load static %}
{% for _ in "x"|rjust:review.mark %}
  <img src="{% static 'core/img/star-yellow.svg' %}" alt="star" />
{% endfor %}
Sign up to request clarification or add additional context in comments.

2 Comments

rjust add review.mark spaces before "x", so i think i should add review.mark - 1 spaces to get correct iteration?
@Vladyslav yeah, is it worked for you ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.