[Answered ]-Show only link to file which exists Django Python

1👍

JavaScript won’t help you here as the error occurs at the server side during rendering. You can simply put the HTML for the file in an if template tag [Django docs]:

{% if post.file_1 %}
    <p class="article-content mb-1"><strong>Datoteka 1: </strong><a href="{{post.file_1.url}}" download>Preuzmi</a></p>
{% endif %}
{% if post.file_2 %}
    <p class="article-content mb-1"><strong>Datoteka 2: </strong><a href="{{post.file_2.url}}" download>Preuzmi</a></p>
{% endif %}

Leave a comment