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)
<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>
~/public_html/cgi-bin/101/9/hello/Hello.py (simplified)
#!/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 )

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




      Maybe if we tell people the brain is an app,    
      they’ll start using it.