Tuesday, May 8, 2012

How to correctly use static files in bottle templates?

I am able to download the css file mentioned in my template, but the page renders as if the browser was unable to access the stylesheet.



Here is my directory structure:



/myapp
myapp.py
bottle.py
views
template.tpl
styles
main.css


here is the relevant line from the template:



<link rel="stylesheet" type="text/css" href="main.css" />


and I have this in myapp.py



from bottle import route, run, debug, template, error, static_file


@route('/styles/<filename>')
def send_css(filename):
return static_file(filename, root='styles')

@route('/')
def index():
return template('template')

debug(True)
run(host='localhost', port=8080, reloader=True)




No comments:

Post a Comment