Guido van Rossum | 6807721 | 2002-10-16 21:01:27 +0000 | [diff] [blame] | 1 | #!/usr/local/bin/python |
| 2 | |
| 3 | """CGI test 2 - basic use of cgi module.""" |
| 4 | |
| 5 | import cgitb; cgitb.enable() |
| 6 | |
| 7 | import cgi |
| 8 | |
| 9 | def main(): |
| 10 | form = cgi.FieldStorage() |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 11 | print("Content-type: text/html") |
| 12 | print() |
Guido van Rossum | 6807721 | 2002-10-16 21:01:27 +0000 | [diff] [blame] | 13 | if not form: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 14 | print("<h1>No Form Keys</h1>") |
Guido van Rossum | 6807721 | 2002-10-16 21:01:27 +0000 | [diff] [blame] | 15 | else: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 16 | print("<h1>Form Keys</h1>") |
| 17 | for key in list(form.keys()): |
Guido van Rossum | 6807721 | 2002-10-16 21:01:27 +0000 | [diff] [blame] | 18 | value = form[key].value |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 19 | print("<p>", cgi.escape(key), ":", cgi.escape(value)) |
Guido van Rossum | 6807721 | 2002-10-16 21:01:27 +0000 | [diff] [blame] | 20 | |
| 21 | if __name__ == "__main__": |
| 22 | main() |