[Zope] Return image from Python Script

Thomas Schorr t_schorr at gmx.de
Tue Dec 14 10:08:23 EST 2004


On Tuesday 14 December 2004 15:56, Andy Yates wrote:
> > How do I return an actual image file from within a Python Script?
> >
> >
> >
> > return context.restrictedTraverse('/LDML/images/ldml.gif')
> >
> >
> >
> > Gives me:
> >
> >
> >
> > <img src="http://127.0.0.1:8080/LDML/images/ldml.gif" alt="" title=""
> >
> > height="120" width="120" border="0" />
> >
> >
> >
> > But what I actually want to do is return the file itself. Think Python
> >
> > Script as symbolic link.
> >
> >
> >
> > Sorry, must be v. easy but I've been thrashing around on various sites
> >
> > for about an hour now and I'm getting no closer.
>
> context.REQUEST.RESPONSE.setHeader('content-type',context.image_file.con
> tent_type)
>
> return context.image_file.data
>
>
>
> BTW, this is a case where file extensions complicate things.
>
>
>
> Andy

isn't the index_html method of OFS.File appropriate?

return getattr(context, 'test.png').index_html(context.REQUEST, 
context.REQUEST.RESPONSE)

index_html should also care for setting the Content-Type http-header.


Thomas


More information about the Zope mailing list