Search code examples
pythonflaskfavicon

my route /favicon.ico not working in my flask instance


Here is my flask code:

@app.route('/favicon.ico')
def favicon():
# my icons are in static/icons, so the favicon file is: static/icons/favicon.ico
return send_from_directory(os.path.join(app.root_path, 'static', 'icons'),
                           'favicon.ico', mimetype='image/vnd.microsoft.icon')

if I go to http://:8080/favicon.ico, I see the icon when running flask, but when I go to one of the other flask-served pages, I see the generic icon. I thought that the route /favicon.ico should work for all pages served by the flask instance.


Solution

  • when you do that route the icon will apply only on 127.0.0.1:8080/favicon.ico but other pages will not be affected

    the solution
    you can add...

    <link rel="icon" href="static/icons/favicon.ico" sizes="32x32">
    

    for each html page
    or simply add it to base file if you are using jinja2