LetterType.cgi: Difference between revisions
No edit summary |
No edit summary |
||
Line 33: | Line 33: | ||
""" | """ | ||
</source> | </source> | ||
[[techdazecgi:lettertype.cgi | | [[techdazecgi:lettertype.cgi | See this script]] | ||
Note how the "clear" links works by clearing all state. | Note how the "clear" links works by clearing all state. |
Latest revision as of 16:49, 9 February 2009
Example of a simple "typing" interface using CGI. Two variables are used for state, one to represent the "current word", and a second to represent the "current letter" to be typed.
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
fs = cgi.FieldStorage()
curword = fs.getvalue("curword", "")
addletter = fs.getvalue("addletter", None)
if addletter:
curword += addletter
print "Content-type: text/html; charset=utf8"
print
print "<html><head><title>lettertype</title></head><body>"
letters = "abcdefghijklmnopqrstuvwxyz"
print "<p>"
for l in letters:
print """<a href="?curword=%s&addletter=%s">%s</a>""" % (curword, l, l)
print """<a href="?">clear</a>"""
print "</p>"
print "<h2>%s</h2>" % curword
print """
</body>
</html>
"""
Note how the "clear" links works by clearing all state.
Exercise
Implement a "backspace" link.