在没有HTML的情况下将图标添加到Flask服务器 [英] Adding a favicon to a Flask server without HTML
问题描述
我的烧瓶服务器不断报告
My flask server constantly reports
xx.xxx.xxx.xxx - - [DD/MM/YYYY HH:MM:SS] "GET /favicon.ico HTTP/1.1" 404 -
在我添加的Flask服务器的代码中,
In the code for my flask server I've added,
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico', mimetype='image/vnd.microsoft.icon')
并且我已将名为favicon.ico
的收藏夹添加到我的烧瓶服务器运行所在的目录中.
and I've added a favicon titled favicon.ico
to the same directory that my flask server is running from.
如果我尝试导航到http://www.myurl.com/favicon.ico
,则会收到404.我的Flask服务器未提供html登陆页面,因此无法在任何地方添加<link rel='shortcut icon' href='favicon.ico' type='image/x-icon'/ >
.我并不真的在乎是否有一个favicon,我只是想阻止错误出现.如何提供网站图标/阻止错误?
If I try to navigate to http://www.myurl.com/favicon.ico
I get a 404. My flask server isn't serving an html landing page so I can't add <link rel='shortcut icon' href='favicon.ico' type='image/x-icon'/ >
anywhere. I don't really care about actually having a favicon, I just want to stop the error from showing up. How can I serve a favicon/stop the error?
推荐答案
将图标作为favicon.ico放入您的静态目录中.及以下python文件中的代码
Put the icon in your static directory as favicon.ico. and below code in python file
import os
from flask import send_from_directory
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico',mimetype='image/vnd.microsoft.icon')
href- http://flask.pocoo.org/docs/0.12/patterns/favicon/
href - http://flask.pocoo.org/docs/0.12/patterns/favicon/
这篇关于在没有HTML的情况下将图标添加到Flask服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!