简体   繁体   中英

Use value from javascript on html page to execute python script

I have a problem. I have a project that involves sending a value from a web page to a web server and using that value to generate a voltage by commanding a digital to analog converter. For the server side I am using a Python script that works very well and I have created a simple web page in which I can enter the value wanted. But the link between them is missing. I am trying to understand CGI scripts to use them for parsing the value from the web page to the Python script but with no luck. Does anyone have any other ideas or can anyone explain CGI for beginners? Thank you.

Here is a simple Python script that pipes the output of a locally executed command ( dir on a Windows computer in this case) via a web request (using the excellent web.py library):

import web
from subprocess import check_output

urls = (
    '/', 'index'
)
app = web.application(urls, globals())

class index:
    def GET(self):
        return '<pre>'+check_output('dir', shell=True)+'</pre>'

if __name__ == "__main__":
    app.run()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM