Python Forum
How to access py script variables through web app ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access py script variables through web app ?
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,214 Apr-20-2023, 05:27 PM
Last Post: farshid
  How to access a web service from a python script? dangermaus33 6 3,116 Dec-04-2020, 07:04 AM
Last Post: dangermaus33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020