Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving static files on heroku

I'm writing a Python app for heroku. Flask is used for the web component of the app.

My problem is that I can't find a way to serve static files. I don't want to do it through flask because that is very inefficient.

I'm also using gunicorn. How would I set up serving of static files?

like image 884
Anton Avatar asked Jan 30 '13 01:01

Anton


People also ask

Can Heroku serve static files?

Clearly, static files (defaults to index. html) can't be served directly on Heroku. So we need to transform static web app into any of these supported web apps. The simplest alternative is to use Node.

How do I get static on Heroku?

Collectstatic during builds When a Django application is deployed to Heroku, $ python manage.py collectstatic --noinput is run automatically during the build. A build will fail if the collectstatic step is not successful.

How do I host a Django media file?

Unfortunately, the Django development server doesn't serve media files by default. Fortunately, there's a very simple workaround: You can add the media root as a static path to the ROOT_URLCONF in your project-level URLs.


1 Answers

Try using Amazon s3 for storing static and media files. A similar question and answer can be found here. Here is heroku's documentation of using s3. Then you might want to disable automatic collectstatic instructions here so collectstatic isn't run every time you push to heroku. Hope this helps.

like image 91
GetItDone Avatar answered Oct 07 '22 04:10

GetItDone