Skip to content

Commit 93ec9a3

Browse files
author
neotycoder
committed
Adding Python CGI Example
This example shows how to grab form data from an html file and use python as a CGI script.
1 parent 72dc3d7 commit 93ec9a3

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

pythonCGI_Example/cgiPython.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/python
2+
3+
# Import CGI and CGITB
4+
import cgi, cgitb
5+
6+
# Create a form object
7+
form = cgi.FieldStorage()
8+
9+
# Get form data Full Name and Favorite TV Show
10+
fullname = form.getvalue('fullname')
11+
tvShow = form.getvalue('tvShow')
12+
13+
print "Content-type:text/html\r\n\r\n"
14+
print "<html>"
15+
print "<head>"
16+
print "<title>TV Viewer Profile</title>"
17+
print "</head>"
18+
print "<body>"
19+
print "<h2>Hello "+str(fullname) +"</h2>"
20+
print "<p> Your favorite TV show is: "+str(tvShow)
21+
print "</body>"
22+
print "</html>"

pythonCGI_Example/form.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<HTML>
2+
<HEAD>
3+
<TITLE>FORM EXAMPLE</TITLE>
4+
</HEAD>
5+
<BODY>
6+
<FORM action="cgi-bin/cgiPython.py" method="post">
7+
Full Name: <input type="text" name="fullname"><BR>
8+
Favorite TV Show: <input type="text" name="tvShow"><br>
9+
<input type="submit" value="Submit" />
10+
</FORM>
11+
</BODY>
12+
</HTML>

0 commit comments

Comments
 (0)