samedi 26 avril 2014

python - impossible de charger des fichiers statiques avec bouteille sur élastique haricot magique - Stack Overflow


After some help, I got my bottle application running with Elastic Beanstalk. Well almost - I still can't see any static files. I have followed the instructions here by inserting a file called python.conf in directory .ebextensions with this in it:


option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"

Unfortunately that did not work. My files are in folders under /static (for example, /static/js, /static/css etc). In my bottle application, I was serving static files as per the answer here, like this:


@route('/static/:path#.+#')
def server_static(path):
return static_file(path, root='./static')

It all works when I run it locally. Does anyone know what I'm doing wrong? Should I be following a different procedure because my static files are in subfolders, or because I'm using bottle instead of flask? I'm aware of a similar question that has been asked here for flask, but there has been no answer (and for all I know it could be a totally different issue). Thanks a lot, Alex




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



After some help, I got my bottle application running with Elastic Beanstalk. Well almost - I still can't see any static files. I have followed the instructions here by inserting a file called python.conf in directory .ebextensions with this in it:


option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"

Unfortunately that did not work. My files are in folders under /static (for example, /static/js, /static/css etc). In my bottle application, I was serving static files as per the answer here, like this:


@route('/static/:path#.+#')
def server_static(path):
return static_file(path, root='./static')

It all works when I run it locally. Does anyone know what I'm doing wrong? Should I be following a different procedure because my static files are in subfolders, or because I'm using bottle instead of flask? I'm aware of a similar question that has been asked here for flask, but there has been no answer (and for all I know it could be a totally different issue). Thanks a lot, Alex



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


0 commentaires:

Enregistrer un commentaire