Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 6 and Version 7 of StaticFiles


Ignore:
Timestamp:
04/29/06 21:37:59 (13 years ago)
Author:
roger.demetrescu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • StaticFiles

    v6 v7  
    1 = Serving Static Files = 
    2  
    3 This document provide infomation about serving static files with {{{TurboGears}}}. 
    4  
    5 There are two ways to serve static files in {{{TurboGears}}}, 
    6  
    7 == Use Static Filter == 
    8  
    9 Edit project_name/config/app.cfg , You'll see there are several static filters exist on  
    10  
    11 {{{  
    12 [/static] 
    13 static_filter.on = True 
    14 static_filter.dir = "%(top_level_dir)s/static" 
    15  
    16 [/favicon.ico] 
    17 static_filter.on = True 
    18 static_filter.file = "%(top_level_dir)s/static/images/favicon.ico" 
     1{{{ 
     2#!html 
     3<br> 
     4<div style="display:block; padding: 4px; border: 2px solid red; color: #C00; font-weight:bold;"> 
     5Note: this entry was moved to TurboGears newsdoc (docs/gs/static.html) 
     6</div> 
     7<br> 
    198}}} 
    20  
    21 The string in square brackets[] denotes the prefered web url. 
    22  
    23 ex: 
    24  
    25 In first case, We can access static files in {{{[/static]}}} as http://localhost:8080/static 
    26  
    27 {{{ 
    28 static_filter.on = True 
    29 }}} 
    30  
    31 The second line "static_filter.on = True" is essential for all static filter statements. 
    32  
    33 {{{ 
    34 static_filter.dir = "%(top_level_dir)s/static" 
    35 }}} 
    36  
    37 We can use "static_filter.file" or "static_filter.dir" to locate the dir or file.  
    38 We can use regular expression by "static_filter.match", too. 
    39  
    40 The static_filter requires all path to be absolute.  
    41 We can use "%(top_level_dir)s" to denote the "top level dir" of this project. 
    42  
    43 We can also specify what content-type to set depending on the extension of each file being served. 
    44  
    45 ex rss file in {{{[/rss]}}}, atom files in {{{[/atom]}}} 
    46  
    47 {{{ 
    48 [/rss] 
    49 static_filter.on = True  
    50 static_filter.content_types = {'rss': 'application/rss+xml'}  
    51 static_filter.dir = '/full/path/to/feed'  
    52  
    53 [/atom] 
    54 static_filter.on = True  
    55 static_filter.content_types = {'atom': 'application/atom+xml'}  
    56 static_filter.dir = '/full/path/to/feed'  
    57 }}} 
    58  
    59 == Use serve_file() function == 
    60  
    61 We might want to have a particular way to serve static content that cannot be achieved via the static_filter. In such case, use the serve_file() function instead. 
    62  
    63 {{{ 
    64 #!python 
    65 from cherrypy.lib import cptools 
    66 cptools.serve_file("filepath") 
    67  
    68 }}}  
    69  
    70 "cptools.serve_file()" let us have more flexibility to control the access of files. 
    71  
    72 This article refer the cherrypy [http://docs.cherrypy.org/serving-static-content serving-static-content] document 
    73  
    74 ---- 
    75  
    76 == Apache Setup == 
    77 To serving of a web application's static content by the web server (Apache) rather than the application server.  
    78  
    79 refer [http://foozle.berkeley.edu/projects/streek/buildtips/serve-static-content-with-apache.html here]