Can't load static files with bottle on elastic beanstalk Can't load static files with bottle on elastic beanstalk flask flask

Can't load static files with bottle on elastic beanstalk


I'm sure it isn't the most elegant solution, but I solved this by putting all of my static files in an S3 bucket and using that in all of my pages.

I didn't really have that many static files to begin with so it wasn't a very big deal. I just made a variable of the S3 bucket url:

S3Static = r'mystaticbucket.s3-us-west-2.amazonaws.com'

Passed it to my bottle templates, and changed the links from:

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

to

<link rel="stylesheet" type="text/css" href = "{{S3Static}}/static/css/Style.css">

(ie just added {{S3Static}} before the path)If you're using a static file in a separate %included header template like I am, you have to pass the S3Static variable to the template like this:

%include header.tpl S3Static=S3Static

And that was about it. I know this won't be an ideal solution for everyone and there are probably better ways to do it, but it's worked for me so far.Thanks,Alex


You should really look into python's whitenoise module. Then you only have one line you have to change and the URL routing is handled by whitenoise next to bottle. Essentially you can keep the url the same as your domain, even if whitenoise is pulling from someplace else. PLus it's designed to cache your static data. Definitely should be using it. It takes like 3 lines to setup, and you can remove bottle's static folder route.