Appendix, How do I serve static files in web.py, in my index.py file the
code as below:
"""register serve"""
urls=('/', 'index',
'/favicon.ico','favicon',
'/(js|css|img)/(.*)', 'static')
"""def class to support serve"""
class static:
def GET(self, media, fn):
rmod="r"
if fn.endswith(".png"):
rmod="rb"
f = open(media+'/'+fn, rmod)
try:
stream = f.read()
return stream
except:
f.close()
return '404 Not Found'
class favicon:
def GET(self):
f = open("static/favicon.ico", 'rb')
return f.read()
Then in my template html file use these static file server:
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/bootstrap.js"></script>
在 2014年6月19日星期四UTC+8下午6时39分07秒,Diego Ke写道:
>
> Hi, All,
> Recently, I used web.py to build my application, then I found that
> log in my serving:
>
> 10.18.40.100:49458 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /css/bootstrap.css" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /css/bootstrap-responsive.css" - 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /js/jquery-1.8.2.min.js" - 200 OK
> 10.18.40.100:49461 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /js/bootstrap.js" - 200 OK
> 10.18.40.100:49461 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /img/mini.png" - 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET
> /img/test_mini.png" - 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:45] "HTTP/1.1 GET /favicon.ico"
> - 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:52] "HTTP/1.1 GET /compeval" -
> 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:52] "HTTP/1.1 GET
> /css/bootstrap.css" - 200 OK
> 10.18.40.100:49458 - - [19/Jun/2014 17:03:52] "HTTP/1.1 GET
> /js/bootstrap.js" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:52] "HTTP/1.1 GET
> /js/jquery-1.8.2.min.js" - 200 OK
> 10.18.40.100:49461 - - [19/Jun/2014 17:03:52] "HTTP/1.1 GET
> /css/bootstrap-responsive.css" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:53] "HTTP/1.1 GET
> /img/mini.png" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:53] "HTTP/1.1 GET
> /img/glyphicons-halflings.png" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:53] "HTTP/1.1 GET /favicon.ico"
> - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /viewcompqlab" - 200 OK
> 10.18.40.100:49459 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /css/bootstrap.css" - 200 OK
> 10.18.40.100:49461 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /css/bootstrap-responsive.css" - 200 OK
> 10.18.40.100:49460 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /js/bootstrap.js" - 200 OK
> 10.18.40.100:49458 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /js/jquery-1.8.2.min.js" - 200 OK
> 10.18.40.100:49458 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET
> /img/mini.png" - 200 OK
> 10.18.40.100:49458 - - [19/Jun/2014 17:03:58] "HTTP/1.1 GET /favicon.ico"
> - 200 OK
> 10.18.40.100:49517 - - [19/Jun/2014 17:07:05] "HTTP/1.1 GET /compeval" -
> 200 OK
> 10.18.40.100:49517 - - [19/Jun/2014 17:07:05] "HTTP/1.1 GET
> /css/bootstrap.css" - 200 OK
> 10.18.40.100:49519 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET
> /js/jquery-1.8.2.min.js" - 200 OK
> 10.18.40.100:49518 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET
> /css/bootstrap-responsive.css" - 200 OK
> 10.18.40.100:49520 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET
> /js/bootstrap.js" - 200 OK
> 10.18.40.100:49520 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET
> /img/mini.png" - 200 OK
> 10.18.40.100:49518 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET
> /img/glyphicons-halflings.png" - 200 OK
> 10.18.40.100:49518 - - [19/Jun/2014 17:07:06] "HTTP/1.1 GET /favicon.ico"
> - 200 OK
>
> It seems that global static files were transfered in every request. But
> obviously that png, ico, js and css fiels is static and global valid.
>
> So my question is: how can I add cache function with my server's static
> files?
>
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.