How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage?

后端 未结 9 1555
生来不讨喜
生来不讨喜 2020-12-25 13:34

I\'m a hobbyist (and fairly new) programmer who has written several useful (to me) scripts in python to handle various system automation tasks that involve copying, renaming

9条回答
  •  遥遥无期
    2020-12-25 14:38

    This simple approach requires nothing except Python standard library. Create this directory structure:

    .
    |-- cgi-bin
    |   `-- script.py
    |-- index.html
    `-- server.py
    

    You put your scripts in "cgi-bin" directory, "index.html" contains links to scripts in "cgi-bin" directory (so you don't have to type them manually, although you could), and "server.py" contains this:

    import CGIHTTPServer
    CGIHTTPServer.test()
    

    To run your server, just run "server.py". That's it, no Apache, no other dependencies.

    HTH...

提交回复
热议问题