[Grok-dev] image files in a folder

Jan-Wijbrand Kolman janwijbrand at gmail.com
Sat Jul 17 11:43:24 EDT 2010

On 7/13/10 17:54 PM, Uwe Hentzschel wrote:
> Hash: SHA1
> Hi,
> i have many image files in a folder like '/Users/uhe/images'. I have to
> manipulate the files with PIL. How can a pagetemplate show images from
> a folder (not the "static" folder.). It is not nessery to save the
> manipulated images.

One way to do it would be something like this:

class SomeImage(grok.View):
   def render(self):
     # This will return an file object as the response content.
     # Zope knows how to deal with returning file contents.
     return open('path/to/image.png')

In you pagetemplate you can then do something like:

   <img src="" tal:attributes="python: view.url('someimage')" />

But you might be better of by registering a DirectoryResource for the 
directory holding your images.

regards, jw

More information about the Grok-dev mailing list