Flask static_folder hosted on S3


Question

I am trying to reroute all of my /static content to host on Amazon S3. My first thought was to use global config['path'] throughout my jinja templates, but this won't work for external css and js files, plus it is kind of messy. I found the static_folder and static_url_path released in 0.7 and this seems like what I want. However, when I go to http://localhost:8000/static/img/abc.jpg it does not locate the files on S3. Am I using this feature right or is there some other way to do this?

Thanks!

1
13
2/25/2012 7:11:30 AM

I recently developed a Flask extension to deal with just this situation. It's called Flask-S3, and you can read the documentation for it here.

As an example, here is how you would integrate it into your Flask application:

from flask import Flask
from flask_s3 import FlaskS3

app = Flask(__name__)
app.config['S3_BUCKET_NAME'] = 'mybucketname'
s3 = FlaskS3(app)

You can use the extension to upload your assets to your chosen bucket:

>>> from my_application import app
>>> from flask_s3 import create_all
>>> create_all(app)

Flask-S3 is blueprint aware, and will upload all assets associated with any registered blueprints.

8
10/28/2012 12:36:52 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon