summaryrefslogtreecommitdiffstats
path: root/Demo/cgi/cgi2.py
blob: 8aa57b37a79bddb00bc16e07cd736f95c6521fc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3

"""CGI test 2 - basic use of cgi module."""

import cgitb; cgitb.enable()

import cgi

def main():
    form = cgi.FieldStorage()
    print("Content-type: text/html")
    print()
    if not form:
        print("<h1>No Form Keys</h1>")
    else:
        print("<h1>Form Keys</h1>")
        for key in form.keys():
            value = form[key].value
            print("<p>", cgi.escape(key), ":", cgi.escape(value))

if __name__ == "__main__":
    main()