How to return an html file in bottle server?
12,129
from bottle import static_file
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='/path/to/your/static/files')
This is the code that the Bottle docs give for serving a static file.
Author by
Ramis
Updated on June 11, 2022Comments
-
Ramis about 2 years
So I have a bottle web framework running but I would like to have one webpage in it.
I have already created the webpage in html and css but I'm not sure how to make bottle use it. I have it displaying just the html but the css part of it does not work.
I've tried googling around but I can't seem to find an example of this.
@get('/test') def test(): return static_file('index.html' , root="views")
My css files are in the same directory as the views folder.
-
Ramis over 10 yearsI know how do to that and it returns my html and it works fine but my css doesn't work. Which is my main concern.
-
Ramis over 10 yearsYea, it was the reason I choose bottle at the beginning but I now need one webpage with my api. I don't really have the time to change the web framework.
-
unholysampler over 10 years@Ramis Is your .css file also in the same directory? Posting the code you are using to call
static_file()
and description of the folder hierarchy would make it easier to debug. -
Ramis over 10 yearsadded to original post
-
Ramis over 10 yearsThanks, using static file I figured out that I had to make a route to my css and images files. After that everything works.