Django Deploying with Heroku


Example

  1. Download Heroku Toolbelt.

  2. Navigate to the root of the sources of your Django app. You'll need tk

  3. Type heroku create [app_name]. If you don't give an app name, Heroku will randomly generate one for you. Your app URL will be http://[app name].herokuapp.com

  4. Make a text file with the name Procfile. Don't put an extension at the end.

    web: <bash command to start production server>
    

    If you have a worker process, you can add it too. Add another line in the format: worker-name: <bash command to start worker>

  5. Add a requirements.txt.

  • If you are using a virtual environment, execute pip freeze > requirements.txt
  • Otherwise, get a virtual environment!. You can also manually list the Python packages you need, but that won't be covered in this tutorial.
  1. It's deployment time!

    1. git push heroku master

    Heroku needs a git repository or a dropbox folder to do deploys. You can alternatively set up automatic reloading from a GitHub repository at heroku.com, but we won't cover that in this tutorial.

    1. heroku ps:scale web=1

    This scales the number of web "dynos" to one. You can learn more about dynos here.

    1. heroku open or navigate to http://app-name.herokuapp.com

    Tip: heroku open opens the URL to your heroku app in the default browser.

  2. Add add-ons. You'll need to configure your Django app to bind with databases provided in Heroku as "add-ons". This example doesn't cover this, but another example is in the pipeline on deploying databases in Heroku.