3

I have a Python Flask web app. Whenever I visit any of the endpoints via my chrome browser, a GET request is invoked to retrieve the webpage (this is expected), but then, it appears Chrome sends a follow-up GET request for a favicon.ico to the same endpoint Chrome just hit.

For example, my app exoses the following endpoint at route / (shown below):

# General Landing Page
@app.route('/')
def index():
    return render_template("index.html", title="Home")

When I hit this endpoint with my Google Chrome, the index.html page is returned just fine. But my log messages show the following:

 env FLASK_APP=app/routes.py flask run --port 5001
 * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
127.0.0.1 - - [18/Feb/2020 23:15:23] "GET / HTTP/1.1" 200 -
[2020-02-18 23:15:23,647] ERROR in app: Exception on /favicon.ico [GET]
Traceback (most recent call last):

As you can see, the / endpoint is hit and returns a status code of 200 OK, but then a subsequent call to favicon.ico errors out. How does one handle this?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Vismark Juarez
  • 613
  • 4
  • 14
  • 21

1 Answers1

5

The favicon.ico is the default file name for an icon used to display on the browser tabs or bookmarks.

If you want to put an icon, you can create one with the name favicon.ico and place it in the static directory of the application. And put a link tag in your html file.

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

Follow this link for more info from flask docs.

And follow this question if you are looking for skipping this GET request

Ejaz
  • 1,504
  • 3
  • 25
  • 51