Static Form Web Page (friends.htm) : form « CGI Web « Python Tutorial






<HTML><HEAD><TITLE>
CGI Demo
</TITLE></HEAD>
<BODY><H3>Friends list for: <I>NEW USER</I></H3>
<FORM ACTION="/cgi-bin/friends1.py">
<B>Enter your Name:</B>
<INPUT TYPE=text NAME=person VALUE="NEW USER" SIZE=15>
<Paragraph><B>How many friends do you have?</B>
<INPUT TYPE=radio NAME=howmany VALUE="0" CHECKED> 0
<INPUT TYPE=radio NAME=howmany VALUE="10"> 10
<INPUT TYPE=radio NAME=howmany VALUE="25"> 25
<INPUT TYPE=radio NAME=howmany VALUE="50"> 50
<INPUT TYPE=radio NAME=howmany VALUE="100"> 100
<Paragraph><INPUT TYPE=submit></FORM></BODY></HTML>

File: friends1.py

#!/usr/bin/env python

import cgi

reshtml = '''Content-Type: text/html\n
<HTML><HEAD><TITLE>
CGI Demo
</TITLE></HEAD>
<BODY><H3>Friends list for: <I>%s</I></H3>
Your name is: <B>%s</B><Paragraph>
You have <B>%s</B> friends.
</BODY></HTML>'''

form = cgi.FieldStorage()
who = form['person'].value
howmany = form['howmany'].value
print reshtml % (who, who, howmany)








22.3.form
22.3.1.A Simple Form
22.3.2.Creating Self-Posting CGI Scripts
22.3.3.Static Form Web Page (friends.htm)
22.3.4.Demonstrates get method with an XHTML form
22.3.5.Demonstrates post method with an XHTML form
22.3.6.Demonstrates use of cgi.FieldStorage with an XHTML form
22.3.7.List form data
22.3.8.Login form
22.3.9.Receiving Data from an HTML File