Don't put favicon.ico into {% compress %}{% endcompress %}, or it won't show

created at March 12, 2021, 9:25 a.m.

Interestingly, I found this problem after deploying my django project. Because  the django-compress works only in production mode.

Problem

your icon won't show as espected if you put the icon link into the compress template tag:

{% compress css %}
    <link href="{% static 'images/favicon.ico' %}" rel="icon"> <!-- icon -->

    <link href="{% static 'css/project.css' %}" rel="stylesheet" type="text/css">
    {% block css %}{% endblock css%}
{% endcompress %}

Solution

simply put the icon link outside the compress template tag:

<link href="{% static 'images/favicon.ico' %}" rel="icon"> # icon
{% compress css %}
    <link href="{% static 'css/project.css' %}" rel="stylesheet" type="text/css">
    {% block css %}{% endblock css %}
{% endcompress %}

restart your project and you will see your icon.

Please log in to leave a comment.