New domain and blog

New domain and blog
Please head over to my new domain to view my blog and current projects

Monday, 22 April 2013

Route static files for BottlePy web framework

I have been using BottlePy on my Raspberry Pi for quite some time. I really like the simplicity of the framework and the ease at which you can get something up and running. The one issue I had, was that you could not load static css or js files. 

There are ways around this, like placing your files in Gist and linking to the raw code, but this can be an issue when you want to run your webserver 'offline'. The documentation is not very clear on how to do this, so here is what I did to get it working properly. 

This is the template that I use to route the static files. This is part of my main python code that runs the server.

Then all you need to do is add your file names in the .tpl file. By doing this, your css, or js files can be stored locally so they can still be served if you are offline. 

That is about it. I hope this helps because I really find this framework great to use and works flawlessly on my Raspberry Pi.

Greg

No comments:

Post a Comment