[Welcome] [TitleIndex] [WordIndex

Problem

You want to be able to refer to image files in your generated HTML files.

Solution

Expose the files in a directory with the following steps:

  1. Declare a variable as an instance of class StaticDirectory.

  2. Export the variable in _q_exports.

Then, refer to a file in the directory, for example, with <img src=...>.

Here is an example:

_q_exports = ['images_dir', ... ]

from quixote.util import StaticDirectory

o
o
o

images_dir = StaticDirectory("/Quixote/myapp/images", list_directory=1)

Now you can generate HTML code that looks like the following:

<img src="/images_dir/pyfav.gif" alt="bad icon"/>

Which will look for the pyfav.gif file in the directory /Quixote/myapp/images.

The StaticDirectory constructor also responds to the following keyword arguments:

Discussion

StaticDirectory exposes all the files in a directory. To expose a single file, use StaticFile instead.


CategoryCookbook CategoryQuixote1


2010-09-22 22:14