在 Flask 应用程序中看不到 Favicon

Favicon not seen in Flask app

我的 Flask 应用程序提供的页面上当前未显示该图标。我有以下两条路线,如何确保显示图标?

@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')

使用以下 <link> 标签在您的 jinja2 模板中指定您的网站图标。确保 href 设置为您在问题中编写的 URL 规则 (/favicon.ico)

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

如果您在@Sean Pianka 示例中进行复制和粘贴,您可能会考虑在 href 中添加双引号,为了区分,可能对其中的项目使用单引号,例如 href="{{ url_for('static', filename='favicon.ico') }}" .虽然 href 允许不带引号的值,但对我来说,没有它们这个字符串就失败了。