[Zope] zpt encoding and content-type
dieter at handshake.de
Wed Oct 22 15:05:56 EDT 2003
Bernd Dorn wrote at 2003-10-22 11:07 +0200:
> i use PageTemplateFile in my python product. now I'm wondering if there
> is some way to redefine the content-type and the encoding of the
> response object in the file
> i tried the suggestion on zopelabs, to set it like the following
> somewhere in a tal:replace::
> python:request.response.setHeader ...
I should give you an "AttributeError", as "response" needs to
be spelled "RESPONSE".
> but this does not affect my response.
There has been a bug in earlier PageTemplate versions
which were overriding a given "Content-Type".
This bug should be fixed in Zope 2.6.2.
> it seems that PageTemplateFile
> always uses text/xml if an xml PI is on the top of the source file. It
> sniffs the content-type from the PI.
> what I basically want to do is, to define the encoding in the xml PI
> (e.g <?xml version="1.0" encoding="iso-8859-1"?>) so that I dont get
> unicode conversion errors (ascii out of range ...) when the file is read
> but this results in a text/xml content type
I do not think that the XML declaration is generated automatically.
You must do it which the correct "encoding".
When you know that you are strictly working in an "iso-8859-1" context,
you can set Python's default encoding to "iso-8859-1"
("sys.setdefaultencoding") in your
"sitecustomize.py" file. Read the "site.py" documentation, for details.
Be warned, that some of the Python Gods do not like this feature
and my drop it sometimes in the future.
Otherwise, ensure that all non-ASCII strings are unicode strings
and set the correct "Content-Type" header (including the correct
charset). In this case, ZPublisher should automatically
encode the result correctly. Search for "unicode support" on Zope.org.
More information about the Zope