B
B
bituke2021-09-14 20:59:47
Django
bituke, 2021-09-14 20:59:47

How to implement the rendering of the "stars" of the rating?

Good afternoon, 6140e2b06afde344353788.png
I have such stars, you can add a class to them, and they will be "empty".
Through python, I need to implement the rendering of these stars according to the rating. (Let's say if the rate is 3, then 3 stars are on)
how can this be done?
html code:

<div class="course-box_rating">
              <i class="fas fa-star"></i>
              <i class="fas fa-star"></i>
              <i class="fas fa-star"></i>
              <i class="fas fa-star"></i>
              <i class="fas fa-star"></i>
            </div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stefan, 2021-09-15
@bituke

Well, if you need it directly through Python, then I’m afraid there won’t be enough bukaf to describe how to do it, but if you think a little and remember that you have JS on the client, then the questions will disappear by themselves, or, directly in the template through cycles, pass context, type

context = {
    ...
    "stars": 5,
    "rating": 3,
    ...
}

And in the template, draw through the loop, look at the index, as soon as you go beyond it, do not add the class, and that's it

N
Nikita Mokhovikov, 2021-09-15
@mohovoy

Watch this video

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question