Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
like image 944
sshkrv Avatar asked Mar 05 '23 17:03

sshkrv


2 Answers

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>
like image 173
Sean Pianka Avatar answered Mar 16 '23 22:03

Sean Pianka


If you're copying and pasting in the @Sean Pianka example, you might consider adding a double-quote to your href, and to differentiate, perhaps use single-quotes for items inside, like href="{{ url_for('static', filename='favicon.ico') }}". While href allows for unquoted values, for me, this string failed without them.

like image 31
LOlliffe Avatar answered Mar 16 '23 21:03

LOlliffe