On Thu, Jun 19, 2014 at 1:29 PM, Diego Ke <[email protected]> wrote:
> 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>
>

Create a 'static' folder at the same level as your *main* script is,
and drop your css and image files into it.  For additional
information, have a look here[1].


Ciao,

Matteo

[1] http://webpy.org/cookbook/staticfiles

-- 
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.

Reply via email to