How can I get a favicon to show up in my django app?

后端 未结 13 1567
盖世英雄少女心
盖世英雄少女心 2020-12-02 06:50

I just want to drop the favicon.ico in my staticfiles directory and then have it show up in my app.

How can I accomplish this?

I ha

13条回答
  •  独厮守ぢ
    2020-12-02 07:41

    Universal solution

    You can get the favicon showing up in Django the same way you can do in any other framework: just use pure HTML.

    Add the following code to the header of your HTML template.
    Better, to your base HTML template if the favicon is the same across your application.

    
    

    The previous code assumes:

    1. You have a folder named 'favicon' in your static folder
    2. The favicon file has the name 'favicon.png'
    3. You have properly set the setting variable STATIC_URL

    You can find useful information about file format support and how to use favicons in this article of Wikipedia https://en.wikipedia.org/wiki/Favicon.
    I can recommend use .png for universal browser compatibility.

    EDIT:
    As posted in one comment,
    "Don't forget to add {% load staticfiles %} in top of your template file!"

提交回复
热议问题