I have tried reading the docs for Bottle, however, I am still unsure about how static file serving works. I have an index.tpl
file, and within it it has a css f
To serve static files using bottle
you'll need to use the provided static_file
function and add a few additional routes. The following routes direct the static file requests and ensure that only files with the correct file extension are accessed.
from bottle import get, static_file
# Static Routes
@get("/static/css/")
def css(filepath):
return static_file(filepath, root="static/css")
@get("/static/font/")
def font(filepath):
return static_file(filepath, root="static/font")
@get("/static/img/")
def img(filepath):
return static_file(filepath, root="static/img")
@get("/static/js/")
def js(filepath):
return static_file(filepath, root="static/js")
Now in your html, you can reference a file like so:
Directory layout:
`--static
| `--css
| `--fonts
| `--img
| `--js