favicon.ico results in 404 error in flask app

By default, the flask will only serve files on the /static endpoint. You can add a custom view to handle the default /favicon request.

The flask documentation has some more information on this subject:

https://flask.palletsprojects.com/en/1.1.x/patterns/favicon/

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

I ran into a very similar problem. I do not have the necessary points to add a comment to the answer yet. So I'll do it using "Your answer". For those who need a much more specific answer on how to use url_for () here is one way to do it.

<!-- Adding a favicon icon to Flask app -->
<!-- SEE: https://favicon.io/favicon-converter/-->

<link rel="shortcut icon"
      href="{{ url_for('static', filename='favicon.ico') }}">

<link rel="apple-touch-icon"
      sizes="180x180"
      href="{{ url_for('static', filename='apple-touch-icon.png') }}">

<link rel="icon"
      type="image/png"
      sizes="180x180"
      href="{{ url_for('static', filename='favicon-32x32.png') }}">

<link rel="icon"
      type="image/png"
      sizes="16x16"
      href="{{ url_for('static', filename='favicon-16x16.png') }}">

<link rel="manifest"
      href="site.webmanifest">

To generate the necessary files use the following link: https://favicon.io/favicon-converter/ All files were copied into the /static directory.