Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (36 sloc) 1.641 kb
6b3d819 @tzuryby edit
tzuryby authored
1 ---
2 layout: default
3 title: Serving Static Files (such as js, css and images)
4 ---
5
6 # Serving Static Files (such as js, css and images)
7
998efb1 Add link to french translation
nux authored
8 Other languages : [français](/staticfiles/fr) | ...
9
a8390e2 @phatfish Added example for Apache. Tidied.
phatfish authored
10 Problem
11 -------
12 How to serve static files?
6b3d819 @tzuryby edit
tzuryby authored
13
a8390e2 @phatfish Added example for Apache. Tidied.
phatfish authored
14 Solution
15 --------
16
17 ### web.py server
6b3d819 @tzuryby edit
tzuryby authored
18
c2b64cc @jpgorton changed 'server' to 'serve'
jpgorton authored
19 Create a directory (also known as a folder) called <code>static</code> in the location of the script that runs the web.py server. Then place the static files you wish to serve in the static folder.
6b3d819 @tzuryby edit
tzuryby authored
20
a8390e2 @phatfish Added example for Apache. Tidied.
phatfish authored
21 For example, the URL <code>http://localhost/static/logo.png</code> will send the image <code>./static/logo.png</code> to the client.
22
23 ### Apache
24
25 To serve static files with Apache an [Alias](http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias) directive can be used to map the request for a URL to a chosen directory, before it is handled by web.py.
26
27 Here is an example Virtual Host configured on a Unix like system with an Alias directive in effect:
28
29 <VirtualHost *:80>
30 ServerName example.com:80
31 DocumentRoot /doc/root/
32 # mounts your application if mod_wsgi is being used
33 WSGIScriptAlias / /script/root/code.py
34 # the Alias directive
35 Alias /static /doc/root/static
36
37 <Directory />
38 Order Allow,Deny
39 Allow From All
40 Options -Indexes
41 </Directory>
42
43 # because Alias can be used to reference resources outside docroot, you
44 # must reference the directory with an absolute path
45 <Directory /doc/root/static>
46 # directives to effect the static directory
47 Options +Indexes
48 </Directory>
49 </VirtualHost>
Something went wrong with that request. Please try again.