Re: CGI and Unicode

Discussion in 'Python' started by Gilles Lenfant, Jun 23, 2003.

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

    HTH.

    --Gilles

    "Jim Hefferon" <> a écrit dans le message de news:
    ...

    [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>"
    Gilles Lenfant, Jun 23, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Yallop

    Re: CGI and Unicode

    Jeremy Yallop, Jun 23, 2003, in forum: Python
    Replies:
    0
    Views:
    1,232
    Jeremy Yallop
    Jun 23, 2003
  2. Andrew Clover

    Re: CGI and Unicode

    Andrew Clover, Jun 23, 2003, in forum: Python
    Replies:
    1
    Views:
    1,020
    Tyler Eaves
    Jun 24, 2003
  3. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    939
    Grzegorz ¦liwiñski
    Jan 19, 2011
  4. Chirag Mistry
    Replies:
    6
    Views:
    162
    Ollivier Robert
    Feb 8, 2008
  5. Terry Reedy
    Replies:
    0
    Views:
    68
    Terry Reedy
    Jan 7, 2014
Loading...

Share This Page