Raspberry Pi – Python Flask

Python flask

The aim is to display content on the Waveshare touchscreen on the Raspberry Pi. For this the Python module Flask is used. With this it is possible to generate a webside with dynamic Python content and much more.


Create folders and download image.

$mkdir app
$cd app
$mkdir templates
$mkdir static
$cd static
$wget https://nm-projects.de/wp-content/uploads/2015/12/logo.png
$cd ~/app

Create the python flask script file.

$nano test_flask.py

Content of test_”flask.py”.

#!/usr/bin/env python

from flask import Flask, render_template
import datetime
app = Flask(__name__)

def test():
   now = datetime.datetime.now()
   timeString = now.strftime("%Y%m%d%H%M%S")
   dynamicData = {
         'time': timeString
   return render_template('index.html', **dynamicData)

if __name__ == "__main__":
   app.run(host='', port=8080, debug=True)

Now edit the content of the html file.

$nano templates/index.html

Content of “index.html”.

      Test page by NM-Projects.de


Test Page

{{ time }}: Side loaded

After that the folder/file structure should look like this.

$find . -name \* -print

Allow execution of the python script.

$ chmod +x test_flask.py

Execute the python script.

$ ./test_flask.py
 * Running on
 * Restarting with reloader

To automatically start the script and the browser on the start-up of the Raspberry Pi edit the following file.

$ sudo nano /home/pi/.config/lxsession/LXDE/autostart

Append autostart by the following lines.

@xscreensaver -no-splash

@xset s off
@xset -dpms
@xset s noblank


@unclutter -grab -visible


This image shows the result on the touchscreen.


Furthermore it is possible to reach the content from any other device like PCs, Smartphones and Tablets. By simply


In the terminal it is possible to see connections, requests and more. - - [06/Jan/2016 21:40:51] "GET / HTTP/1.1" 200 -

Leave a Reply

Your email address will not be published. Required fields are marked *