[Zope] force charset in HTTP header from ZPT

Hong Yuan hongyuan at homemaster.cn
Mon Aug 16 10:18:53 EDT 2004


Hi,

I have a master template in ZPT for my site with

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

in the <head> section. However, some versions of IE will automatically 
detect some of the pages rendered with the template as charset of 
GB2312, although they will identify other pages using the same template 
correctly. Using 'curl -I' to view the HTTP header sent by ZServer, I 
found the following:

HTTP/1.1 200 OK
Server: Zope/(unreleased version, python 2.3.4, linux2) ZServer/1.1 
Plone/2.0.3
Date: Mon, 16 Aug 2004 14:04:45 GMT
Content-Length: 21824
Etag:
Content-Type: text/html

It seems that the 'charset=utf-8' part is not sent to the browser in the 
http header. Is there an easy way to force Zope to send this part in the 
HTTP header to the client?

I was trying to use request.RESPONSE.setHeader method in the ZPT to set 
this in the HTTP header, but the following syntax

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

leads to the error below:

EOL while scanning single-quoted string (html", line 1) in expression "python:request.RESPONSE.setHeader('content-type', 'text/html", at line 2, column 

Zope is taking the semicolon after 'text/html' as a separator instead 
part of the string. I tried to assign the string to a variable with <div 
tal:define="content_type string:text/html; charset=utf-8" />, but it 
doesn't work neither. How can I work around this?

Hong Yuan


More information about the Zope mailing list