HTML (8.html) ⇒ Python (Hello.py) ⇒ the Web
#!/usr/bin/python # where Python is located at import cgi # importing the CGI module form = cgi.FieldStorage( ) # preparing to read web inputs act = form["act" ].value # which button is clicked on message = form["message"].value # the input message
|
|
<form method="post" target="view1" action="http://undcemcs01.und.edu/~wen.chen.hu/cgi-bin/101/9/hello/Hello.py"> A Hello-World Webpage Using Python print Command print <input type="submit" name="act" value="Run" /> <input type="submit" name="act" value="HTML source"> <input type="submit" name="act" value="Python source"> <input type="submit" name="act" value="Help"> <input type="reset" value="Reset"> <iframe name="view1"></iframe> </form> |
|
|
|
#!/usr/bin/python # # Print the message entered from the Web. # import cgi # CGI module form = cgi.FieldStorage( ) # Reads the HTML form data. act = form["act" ].value message = form["message"].value if ( act == "Run" ): # Print HTML. print( "Content-type: text/html\n\n" ) # Command issued: print( "/usr/bin/python Hello.py '" + message + "'") print( message ) elif ( act == "HTML source" ): print( "Content-type: text/plain\n\n" ) file = open( "/home/wen.chen.hu/public_html/course/101/9/9.html", "r" ) print( file.read( ) ) file.close( ) elif ( act == "Python source" ): print( "Content-type: text/plain\n\n" ) file = open( "Hello.py", "r" ) print( file.read( ) ) file.close( ) elif ( act == "Help" ): print( "Content-type: text/html\n\n" ) file = open( "../Help.html", "r" ) print( file.read( ) ) file.close( ) else: print( "Content-type: text/html\n\n" ) print( "No such option: " + act ) |
Maybe if we tell people the brain is an app, they’ll start using it. |