Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: CGI and Unicode (http://www.velocityreviews.com/forums/t318758-re-cgi-and-unicode.html)

Gilles Lenfant 06-23-2003 08:37 PM

Re: CGI and Unicode
 
Thy the patch in the middle of your source...
Works better than a <meta http-equiv... >

HTH.

--Gilles

"Jim Hefferon" <jhefferon@smcvt.edu> a écrit dans le message de news:
545cb8c2.0306231007.4a3c07a2@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>"




All times are GMT. The time now is 05:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.