1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/docs/file-resource.html Mon Nov 06 23:39:49 2006 +0000
1.3 @@ -0,0 +1,15 @@
1.4 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.5 +<html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />
1.6 +
1.7 + <title>DirectoryResource - Serving Static Content</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.8 + <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.9 +<body>
1.10 +<h1>FileResource - Serving Individual Files</h1>
1.11 +<p>The <code>FileResource</code> class provides a means to
1.12 +serve individual static files from the
1.13 +filesystem. Although a <a href="directory-resource.html"><code>DirectoryResource</code></a>
1.14 +object may serve files having specific filename extensions as
1.15 +particular types from a filesystem directory, we sometimes need to
1.16 +select individual files from special locations and serve their
1.17 +contents as part of a response.</p><div class="WebStack"><h3>WebStack API - FileResource Initialisation</h3><p>The <span style="font-family: monospace;">File</span><code>Resource</code> class (found in the <code>WebStack.Resources.Static</code> module) accepts the following parameters when being initialised:</p>
1.18 +<dl><dt><code>filename</code></dt><dd>The full path to the particular static file being served.</dd><dt><code>content_type</code></dt><dd>A content type object (such as <code>WebStack.Generic.ContentType</code>) providing sufficient information for user agents to interpret the file's contents.</dd></dl></div><h2>Combining MapResource with FileResource</h2><p>One might combine <code>MapResource</code> with <code>FileResource</code> to provide a <code>favicon.ico</code> image for an application as follows:</p><pre>from WebStack.Resources.ResourceMap import MapResource<br />from WebStack.Resources.Static import FileResource<br /><br /># This is where the application's resources would be obtained.<br /><br />app_resource = ...<br /><br /># Here is where we combine MapResource and FileResource.<br /># Note that one would not necessarily hard-code directory paths into the application.<br /><br />top_resource = MapResource({<br /> "favicon.ico" : FileResource("/usr/share/apps/MyApp/images/py.ico"), ContentType("image/x-icon")),<br /> "" : app_resource<br /> })</pre><p>In the above example, the <code>favicon.ico</code> file in the <code>images</code> directory is served as <code>image/x-icon</code>.</p></body></html>
1.19 \ No newline at end of file