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

后端 未结 9 1577
生来不讨喜
生来不讨喜 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:34

    This page on the python site has a good description and example of what you need to do to run a python CGI script. Start out with the simplest case first. Just make a short script that prints html.

    #!/usr/bin/python                   #on windows change to your path to the python exe
    
    print "Content-Type: text/html"     # HTML is following
    print                               # blank line, end of headers
    print "CGI script output"
    print "

    This is my first CGI script

    " print "Hello, world!"

    When you try this the first time, the hardest part is usually figuring out where to put the script and how to make the web server recognize and run it. If you are using an apache web sever, take a look at these configuration steps.

    Once you have this simple script working, you will just need to add an html form and button tag and use the action property to point it to scripts you want to run.

提交回复
热议问题