You can write a 'StaticFileHandler' class to handler the static File. 
So you can use any url of static file you want.

urls = (
'/(css|images|js)/(.+)', 'static', 
)

class StaticFileHandler: 
    def GET(self, category, path):
        abspath = os.path.join(root, 'static', category, path)
        if not abspath.startswith(root) or not os.path.exists(abspath):
            raise web.notfound()
        stat_result = os.stat(abspath)
        modified = datetime.datetime.fromtimestamp(stat_result[stat.ST_MTIME])
        ims_value = web.ctx.environ.get("HTTP_IF_MODIFIED_SINCE")
        if ims_value and str(ims_value) >= str(modified):
            raise web.notmodified()
        web.header("Last-Modified", modified)
        web.header("Content-Length", stat_result[stat.ST_SIZE])
        web.header("Cache-Control", "public")
        mime_type, encoding = mimetypes.guess_type(abspath)
        if mime_type: web.header("Content-Type", mime_type)
        return file(abspath).read()


2009-11-02 



shwdai 



发件人: xrfang 
发送时间: 2009-11-01  08:44:44 
收件人: web.py 
抄送: 
主题: [webpy] serving static file 
 
Hi there,
I found a post discussing static file serving. I am also from PHP and
has the same confusion.  I have a thinking, why cannot we use an
internal variable such as web.static_path (which default to "/
static/") to specify which folder is static?  This way, we can specify
more than one static folder such as /styles/, /img/, /downloads/, this
will be handy.  And this static_path variable can be a regex, or a
list/tuple of string/regex.  What do you think?
2ndly, if use webpy with other servers such as apache or the GAE, is
the /static/ file serving directly hand-over to the web server, or it
is still streamed by webpy?
Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to