Python Forum

Full Version: simple html page with update data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello,
need yor help with a simple project ,
I have lighttpd running on my PI and I want to create a webpage with python that will show me updated data from sensors on my PI (and all kind of python code output I'm running)

what will be the best way to make it?

Thanks,
Flask works fine for this.
Here some links from me link1, link2 , link3
Python WebServer With Flask and Raspberry Pi
Just so you know Flask comes with build in web-server,so can develop everything without lighttpd.
If need to make public on web then need to use a production web-server,then Gunicorn can be better choice than lighttpd.
As there are really good tutorials for this How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 20.04
no need for public
this is just for my home private netwrok

no other solution because I'm allready using lighttpd for pi-hole?
or it's best not to mix apps?


Thanks ,
Flask is 100% the best go to here.

If you do something such as:

from flask import Flask

app = Flask(__name__)
@app.route('/')
def home():
    a = 100 + 100
    return a
Then that will show 200 on your webpage in basic text (I think it shows it in HTML's paragraph font/size but can't remember off the top of my head). The URL would be "www.mydomain.com/" aka the Index page or home page, if you wanted to have multiple pages, you can change the "@app.route('/')" to whatever you want it to be, for example if you had a page describing the characteristics of owls, you could do "@app.route('/owls')".

If you link it up to a database, you can then use SQLAlchemy to connect to the DB and the site can be built to automatically update based on the info in the DB. So instead of having to mess with the code, you'd just refresh the page and bam!