How to avoid the 'favicon.ico' not found error in below flask code? I searched few favicon.ico issues but could not resolve this one.
@app.route('/<path:req_path>')
def dir_listing(req_path):
abs_path = os.path.join(UPLOAD_FOLDER, req_path)
# Check if path is a file and serve
if os.path.isfile(abs_path):
return send_file(abs_path, mimetype="application/json")
# Show directory contents
files = os.listdir(abs_path)
return render_template('file_list.html', files=files)
index.html
<!doctype html>
<title>Upload new File</title>
<hr>
<link rel="shortcut icon" href="#" />
<h1>{{message}}</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
<ul>
{% for file in file_list %}
<li><a href="{{ file }}">{{ file }}</a></li>
{% endfor %}
</ul>
file_list.html-
<ul>
{% for file in files %}
<li>
<a href="{{ file }}">{{ file }}</a>
</li>
{% endfor %}
</ul>
By default a browser always look for a /favicon.ico
when opening a website, you would need to serve a favicon file there to get rid of that error.
You can also customize the path following this guide