durusmail: quixote-users: "examples of serving static files"
"examples of serving static files"
2003-05-02
"examples of serving static files"
Andrew Kuchling
2003-05-02
On Fri, May 02, 2003 at 02:10:58PM +0200, VAN DER HEIJDEN Maarten wrote:
>How can I publish a static page or the contents of a directory to the
>quixote demo?

The examples are a bit too concise, aren't they?  Is the following
more helpful?

========================================

A single file
-------------

The ``StaticFile`` class makes an individual filesystem file (possibly
a symbolic link) available.  You can also specify the MIME type and
encoding of the file; if you don't specify this, the MIME type will be
guessed using the standard Python ``mimetypes.guess_type()`` function.
The default action is to not follow symbolic links, but this behaviour
can be changed using the ``follow_symlinks`` parameter.

The following example publishes a file with the URL ``.../stylesheet_css``::

    # 'stylesheet_css' must be in the _q_exports list
    _q_exports = [ ..., 'stylesheet_css', ...]

    stylesheet_css = StaticFile(
            "/htdocs/legacy_app/stylesheet.css",
            follow_symlinks=1, mime_type="text/css")



A directory
-----------

Publishing a directory is similar.  The ``StaticDirectory`` class
makes a complete filesystem directory available.  Again, the default
behaviour is to not follow symlinks.  You can also request that the
``StaticDirectory`` object cache information about the files in
memory so that it doesn't try to guess the MIME type on every hit.

::
    _q_exports = [ ..., 'notes', ...]

    notes = StaticDirectory("/htdocs/legacy_app/notes")

--amk                                                    (www.amk.ca)
I'll bring the Kindly Ones down on his blasted head.
      -- Desire, in SANDMAN #31: "Three Septembers and a January"

reply