Python Forum

Full Version: How to access py script variables through web app ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I wrote a py script (on a raspberry pi) to control some hardware using GPIO pins.
The script will eventually run as a service but is currently running through the commandline (>python3 because of testing purposes.
It has some 'realtime' functionality and therefore running 24/7.

I would like to have a webpage (served by apache or lightppd) that can read (get) or write (post) some variables that are being used in mypscript.

What would be the best way to accomplish this?

Any thoughts/hints are greatly appreciated!

You can use flask (

from flask import Flask, request
app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def test():
    return 'request.args: {} , request.form: {}'.format(request.args ,request.form)
request.form contains the POST data

t@tbox:~$ curl -X POST -d 'x=y'
request.args: ImmutableMultiDict([('a', 'b')]) , request.form: ImmutableMultiDict([('x', 'y')])
the "app" can be called from eg apache using a wsgi script