"is_file" check not working


I've got the following code in my template, which works fine on my computer:

{% if car_image.is_file %}
    <img src="/static/reviews/images/{{ car }}.jpg" class="img-responsive">
{% else %}
    <h2><a href="" class="btn btn-primary btn-lg">Suggest a picture for this car</a></h2>
{% endif %}

However, it doesn't seem to work on PythonAnywhere: Second part of my if statement i.e. suggest button is shown even though that image exists.

If I remove ".is_file", car_image appears without problem.

Any suggestion or feedback will be welcomed and greatly appreciated.

Thank you.

What type of object is car_image?

Ops, sorry!

In my I had:

car_image = Path("C:/Users/Me/Desktop/steerr/static/reviews/images/" + str(car) + ".jpg")

Of course, this worked only on my local computer. I should change it to:

car_image = Path("/home/steerr/steerr/static/reviews/images/" + str(car) + ".jpg")

Now it's all well!

Ah, that would explain it! Glad you worked it out :-)