Nov-16-2020, 07:40 PM
Hello. I am learning Python 3 from a .pdf from Tutorialspoint. I am at a stage where I'm learning how to write CGI programs. I copied the following program, which when run should result in
Here is a simple URL, which passes two values to hello_get.py program using GET method.
going to use the cgi module, which makes it very easy to access the passed information -
Hello ZARA ALISimple URL Example – Get Method
Here is a simple URL, which passes two values to hello_get.py program using GET method.
/cgi-bin/hello_get.py?first_name=Malhar&last_name=LathkarGiven below is the hello_get.py script to handle the input given by web browser. We are
going to use the cgi module, which makes it very easy to access the passed information -
#!/usr/bin/python3 # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') last_name = form.getvalue('last_name') print ("Content-type:text/html") print() print ("<html>)" print ("<head>") print ("<title>Hello - Second CGI Program</title>") print ("</head>") print ("<body>") print ("<h2>Hello %s %s</h2>" % (first_name, last_name)) print ("</body>") print ("</html>">)I modified the code, as it said "invalid syntax":
#!/usr/bin/python3 # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') last_name = form.getvalue('last_name') print ("Content-type:text/html") print() print ("<html>") print ("<head>") print ("<title>Hello - Second CGI Program</title>") print ("</head>") print ("<body>") print ("<h2>Hello %s %s</h2>" % (first_name, last_name)) print ("</body>") print ("</html>")And the result I'm getting now is:
Content-type:text/html <html> <head> <title>Hello - Second CGI Program</title> </head> <body> <h2>Hello None None</h2> </body> </html>