Search code examples
pythonflaskfavicon

Favicon not seen in Flask app


The favicon is currently not being displayed on pages served by my Flask app. I have the following two routes, how do I ensure the favicon is displayed?

@app.route('/')
def hello():
    return redirect("tg://resolve?domain=sneakersale", code=302)

@app.route('/favicon.ico')
def fav():
    return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico')

Solution

  • Use the following <link> tag to specify your favicon within your jinja2 templates. Ensure href is set to the URL rule that you wrote in your question (/favicon.ico)

    <head>
        <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
    </head>