[Product-Developers] Re: Setting a mime-type on a Zope 3 browser view

Derek Broughton derek at pointerstop.ca
Sun Jan 24 04:05:51 UTC 2010


Martin Aspeli wrote:

> Derek Broughton wrote:
> ::
>>
>> No, I really don't care what content type header is sent back - I suspect
>> text/html for the content type might work, but that's well beyond my
>> current
>> problem.  My problem is that TAL, not my browser, is treating the
>> template as HTML rather than XML and therefore lowercases all the tags
>> (using HTMLParser.py).
> 
> Sorry, I misunderstood your question then. I suspect you still want to
> set the response header, but more on that later.
> 
>> A little debugging shows me that the problem is in using the viewlet.  My
>> main view template, Text.pt, starts with<?xml... and is treated as XML. 
>> My viewlet, _cannot_ start with<?xml (generates an error "XML Parsing
>> Error: XML or text declaration not at start of entity" if I add it).
> 
> I would perhaps think that using viewlets to compose an XML document is
> not something viewlets were designed for. 

It wasn't really my intent, it just turned out that a viewlet was a good way 
to include another template at the time.  Then my design changed, and 
simplified, and in the end I ended up with a single template that needed a 
choice of XSL stylesheets, so it was easy enough to remove the viewlet.

> You may have more luck just
> building the document using the tools that come with lxml, although this
> will be more imperative and less template-like.

...
> Maybe instead of using viewlets, you could use ZPT macros? I assume that
> the ZPT parser would read the whole ZPT file and so you coul dhave a
> <?xml ..> header in both, but obviously only the bits inside the
> metal:define-macro would actually be pulled in.

My turn for a D'oh.  It was using a viewlet because there was originally a 
need for a viewlet, but you're absolutely right that this is both a better 
idea, and more suited to my current purpose.

Thanks.

(Still, it doesn't seem right that viewlets can have a different content-
type from the view that invokes them),
-- 
derek





More information about the Product-Developers mailing list