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.
Setup
Create folders and download image.
$cd $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__) @app.route("/") 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='0.0.0.0', 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