Thank you all for replying - now it works I got utf-8 string in my form.

Seem Zopes ZPT system is trying to do the encoding, depending on on setHeader() method.
So if this header is set you can simply return unicode strings.

Strange setting cmf default charset to utf-8 doesn't work :-(

Am Montag, den 23.05.2005, 10:35 +0200 schrieb Joern Wallstabe:


i would like to feed a zpt form with data from a python dictionary via a python script

zpt snippet:

<textarea name="title:record:ulines" rows="3"  cols="65">
<tal:span content="python:context.printDict(here.dict)"/>

This is wrong anyway. Use tal:content in the textarea instead.

o.k. replace that with
<tal:content content="python:context.printDict(here.dict)"/>


python script prinDict:

keys_ = dict.keys()

for key in keys_:
       lines.append(u"%s:%s\n" %(key ,dict[key]))

uni_str = u"".join(lines)
return uni_str.encode('utf-8')

function now returns unicode string without utf-8 encoding

I'm always getting a  UnicodeDecodeError.

I' using Zope 2.7.5, CMF 1.5.1, Python 2.3.5
HTML meta tag is set to
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
CMF default_charset = utf-8

meta charset does not count btw. CMF default should, but it really depends on the real content-type header you send. Make sure its
the encoding you want there (setHeader() )

That was the important hint: added to cmf main_header_template:

tal:define "
dummy python: request.RESPONSE.setHeader('content-type', 'text/html;; charset=utf-8');

And its important to watch the encoding of the strings you work
with. Where does the dictionary come from?

python dictionary was result form parsing xml data into that dictionary (all unicode)

Thanx again :-)

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Zope maillist  -
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to