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.
Hi,

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 myscript.py) 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!

-ben
You can use flask (http://flask.pocoo.org/docs/0.12/quickstart/)
eg

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)

app.run()
request.form contains the POST data

t@tbox:~$ curl -X POST 127.0.0.1:5000?a=b -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