Python Forum
Simple URL Example – Get Method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple URL Example – Get Method
#1
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
Hello ZARA ALI
Simple 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=Lathkar
Given 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>
Reply


Messages In This Thread
Simple URL Example – Get Method - by whois1230 - Nov-16-2020, 07:40 PM
RE: Simple URL Example – Get Method - by ndc85430 - Nov-16-2020, 07:53 PM
RE: Simple URL Example – Get Method - by snippsat - Nov-18-2020, 07:02 PM
RE: Simple URL Example – Get Method - by ndc85430 - Nov-19-2020, 06:44 PM
RE: Simple URL Example – Get Method - by snippsat - Nov-19-2020, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best Method for simple GUI? PythonAndArduino 4 3,652 Nov-17-2017, 06:22 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020