-
Notifications
You must be signed in to change notification settings - Fork 1
MQTT and raspberry charts in a web page step4
New FlaskApp instad of the dumb version
(ONGOING) python3 /var/www/app.py /var/www/app.py import datetime, logging, os, time from flask import Flask, render_template, session, g, request #from flask import request, jsonify from datetime import datetime, timedelta
app = Flask(name,template_folder='templates')
#Random secret key app.config['SECRET_KEY']=os.urandom(24) app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=10) app.config["OTP_ENABLED"] = "False" global COOKIE_TIME_OUT COOKIE_TIME_OUT = 60*5 #5 minutes
logger = logging.getLogger('simple_example') logger.setLevel(logging.DEBUG)
#Ideas #https://www.instructables.com/Python-WebServer-With-Flask-and-Raspberry-Pi/ #http://www.academicdabbling.com/home/dabbles/raspberrypi/raspberrypi220-implementingacertificateauthorityca #https://www.hackster.io/texadactyl/do-it-yourself-certificate-authority-on-a-raspberry-pi-f14ae0 #https://www.educba.com/flask-https/
#Before Requests for Session @app.before_request def before_request(): g.user = None if 'user_id' in session: g.user = session['user_id']
#Logout def logout(): logger.info("logout user") session.pop('user_id', None) logger.info(session) return render_template("index.html")
@app.route('/') def home(): logger.info(session) return render_template('index.html', utc_dt=datetime.utcnow(), ip=request.remote_addr)
@app.route("/df_w_rank_deaths_pml.html", methods=['GET']) def df_w_rank_deaths_pml(): return render_template("/df_w_rank_deaths_pml.html")
if name == 'main': #https adhoc #app.run(ssl_context='adhoc',debug=True, port=8080, host='0.0.0.0') #https with local certificicates app.run(ssl_context=('/etc/ca/certs/ca.cert.pem', '/etc/ca/private/ca.key.pem'),debug=True, port=8080, host='0.0.0.0') #no https #app.run(debug=True, port=8080, host='0.0.0.0')