Solution 1 :

If the h1 text is displaying correctly for all branches of this template, but some of the images are the same then the most likely problem is that the image files are the same image, but with different filenames.

Problem :

I have model class with fields current_value and previous_value.
And then, in template used by listview, inside loop i have code like this:

{% if data.current_value < data.previous_value %}
    <img src="{% static 'app1/negative.png' %}" width="40" height="40">
    <h1>Price down</h1>
{% elif data.current_value > data.previous_value %}
    <img src="{% static 'app1/positive.png' %}" width="40" height="40">
    <h1>Price up</h1>
{% else %}
    <img src="{% static 'app1/neutral.png' %}" width="40" height="40">
    <h1>Price the same</h1>
{% endif %}

H1 text is displayed correctly, image is not. More specific – image for ‘else’ condition i believe is always ok, but for ‘if’ and ‘elif’ is displaying the same picture (one of them).

Confusing and infuriating. What am i doing wrong?

Comments

Comment posted by Nickname11

No, they are not. I have checked it many times and I have checked it now.

Comment posted by Nickname11

What about accessing fields? Both curent_value, and previous_value are models.FloatField(). Mayby i should fetch the value of those fields in different way?

Comment posted by schillingt

Did you check what image is being rendered via a browser’s developer tools and the inspection tool? Otherwise, please post your entire template and an example context that the template is rendered with. It’s not possible to answer your question definitely (outside of my original answer) without more information.

Comment posted by schillingt

The reason being, if your

Comment posted by schillingt

Nope. The images might have been cached though.

By

Leave a Reply

Your email address will not be published. Required fields are marked *