Last week, I spent quite a while getting a simple "Hello World" Django app in place on Heroku. This week, I wanted to see if I could repeat the process by posting a small working demo project. Things went much more smoothly this time around.
git to grab a local clone of the project. I used
virtualenv to setup a virtual environment and
pip to load that environment with the project's requirements.
I created a local PostgreSQL database so I could test things locally. I remembered to set the DATABASE_URL environmental variable and to sync Django with the new database. I debated on whether I needed to run
python manage.py collectstatic in order to move the website's static files (such as scripts and stylesheets), but the site ran fine locally as-is without it.
Since everything seemed to work fine locally, it was time to push to Heroku. I double-checked that
.gitignore was in place with
*.pyc in it. When I ran
git add . I realized that I'd done all of this testing without touching a single project file. That's a neat design.
I created a new heroku app and used git to push the files to heroku. I initially forgot to sync the database on Heroku's end, but the resulting error message was obvious and it only took a minute to correct. To make sure everything really worked, I used Django's default admin interface to add some database contents (a poll with 4 possible answers). Everything seems to be running fine.
Given the light expected traffic, I didn't bother to switch out the default Django server for gunicorn.
All of this took me about 1 hour, compared to last week's 20 hours. Now that I've got this down, maybe Heroku isn't so bad after all!