Django Static Files on Heroku

It’s a fact. Heroku is a great solution for Python web developers. They are the best and truly polyglot hosting solution for web apps. The only thing that took me a while to get working with my Django apps was the static files. I started using S3 as my backend but preferred a simpler solution for very small projects.

I searched around and found a very simple solution.

web: python app/ collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=$PORT app/ 

Just add the collectstatic command to the Procfile.

3 thoughts on “Django Static Files on Heroku”

  1. Hi. Do I have to replace this line:

    web: python hellodjango/ run_gunicorn -b “$PORT” -w 3
    Or just append it to the Procfile?


  2. It may be better to run with `heroku run python app/ collectstatic –noinput` separately as a deployment step along with migrations. Otherwise, you’re going to run every time you spin up a new dyno, and everytime you unidle a dyno. It could be a big performance hit, especially if you’ve got a lot of static files or decide to switch to S3.

    Edit: That is, run collectstatic for every new/unidling dyno.

Leave a Reply