CGI and Unicode

Gilles Lenfant glenfant at NOSPAM.bigfoot.com
Mon Jun 23 22:37:11 CEST 2003


Thy the patch in the middle of your source...
Works better than a <meta http-equiv... >

HTH.

--Gilles

"Jim Hefferon" <jhefferon at smcvt.edu> a écrit dans le message de news:
545cb8c2.0306231007.4a3c07a2 at posting.google.com...

[snip]

>
> What am I missing?  Thanks for any help,
> Jim Hefferon
>
> -------- test_cgi.py ----------------------------
> #!/usr/bin/python -u
> # test_cgi.py
> # test CGI unicode issue
> from types import *
>
> import cgi
> import cgitb
> cgitb.enable()
>
> # create the HTML document
> print "Content-Type: text/html\n\n"

# change above line against...
print "Content-Type: text/html; charset=utf-8\n\n"

> print "<html><head><title>CGI TEST</title></head>\n\n"
> print "<META http-equiv=\"Content-Type\" content=\"text/html;
> charset=UTF-8\">"
> print "<body bgcolor=\"white\">\n"
>
> cgi_params=cgi.FieldStorage()
> cgi_keys=cgi_params.keys()
> try:
>     var=cgi_params['name'].value
>     if type(var) is UnicodeType:
>         print "<p>The type of the variable is a Unicode</p>\n"
>     elif type(var) is StringType:
>         print "<p>The type of the variable is a regular string</p>\n"
>     print "<p>Character 12 is %s</p>\n" % (var[12],)
> except:
>     pass
>
> print "<form method=\"POST\" accept-charset=\"utf-8\">\n"
> print "<input type=\"text\" name=\"name\">\n"
> print "<input type=\"submit\">\n"
> print "</form>\n"
> print "</body></html>"





More information about the Python-list mailing list