A Hello-World Webpage Using Python


The web programs below print the message entered from the Web by using:
HTML (8.html) ⇒ Python (Hello.py) ⇒ the Web

where the CGI function is used to receive the web user inputs via the following code, for example:
   #!/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
  # A Hello-World Webpage Using Python print Command

  print 
           
~/public_html/course/101/9/9.html (simplified)
01<form method="post" target="view1"
02    action="http://undcemcs01.und.edu/~wen.chen.hu/cgi-bin/101/9/hello/Hello.py">
03  A Hello-World Webpage Using Python print Command
04  print <input type="text" name="message" value="Hello, World!" size="24">
05  <input type="submit" name="act" value="Run" />
06  <input type="submit" name="act" value="HTML source">
07  <input type="submit" name="act" value="Python source">
08  <input type="submit" name="act" value="Help">
09  <input type="reset"  value="Reset">
10  <iframe name="view1"></iframe>
11</form>
~/public_html/cgi-bin/101/9/hello/Hello.py (simplified)
01#!/usr/bin/python
02#
03# Print the message entered from the Web.
04#
05 
06import cgi       # CGI module
07 
08form    = cgi.FieldStorage( )     # Reads the HTML form data.
09act     = form["act"    ].value
10message = form["message"].value
11 
12if ( act == "Run" ):
13  # Print HTML.
14  print( "Content-type: text/html\n\n" )
15  # Command issued:
16  print( "/usr/bin/python Hello.py '" + message + "'")
17  print( message )
18 
19elif ( act == "HTML source" ):
20  print( "Content-type: text/plain\n\n" )
21  file = open( "/home/wen.chen.hu/public_html/course/101/9/9.html", "r" )
22  print( file.read( ) )
23  file.close( )
24 
25elif ( act == "Python source" ):
26  print( "Content-type: text/plain\n\n" )
27  file = open( "Hello.py", "r" )
28  print( file.read( ) )
29  file.close( )
30 
31elif ( act == "Help" ):
32  print( "Content-type: text/html\n\n" )
33  file = open( "../Help.html", "r" )
34  print( file.read( ) )
35  file.close( )
36 
37else:
38  print( "Content-type: text/html\n\n" )
39  print( "No such option: " + act )

Review: Client-side Programming Languages
Which is a client-side programming language?
      Java
      JavaScript
      Python
      SQL (Structured Query Language)
Result: