Python Web Development with Flask — Favicon, Background Tasks, and HTTP Method Overrides

John Au-Yeung
3 min readJan 31, 2021
Photo by Patrick Tomasso on Unsplash

Flask is a simple web framework written in Python.

In this article, we’ll look at how to develop simple Python web apps with Flask.

Favicon

We can add a favicon by putting it in the static folder and then referencing it.

For example, we can write:

app.py

from flask import send_from_directory, Flask, render_template
import os
app = Flask(__name__)@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/')
def hello_world():
return render_template('index.html')

templates/index.html

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

Then we put our favicon.ico file into the static folder.

Now we should see the favicon displayed in our browser’s tab.

Deferred Request Callbacks

--

--