W00t, I just deployed my first Django app on Heroku! Only took about a day of debugging, but the tutorial is pretty great.

Full URL of Getting Started with Django:
http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/

By the way, I’d recommend watching the video of the tutorial and using the text below it as review or as a summary of what you’re watching. The text is not fully comprehensive with all the commands, and if you only follow the text you’ll get confused.

Created by Kenneth Love, this Kickstarter-backed Django tutorial was uploaded around January 2013. The first part purports to teach you how to create a small blogging app, and later parts feature larger demonstration projects.

Neither of the Django tutorials I’d visited so far — Coding for Entrepeneurs nor Tango with Django — had visited deployment (to Heroku, no less!) as part of the setup in the beginning, so it was a nice change. Also nice was that this tutorial:

  • uses vagrant on top of Virtualbox and virtualenv, which is a best practice setup for running Django apps nowadays
  • uses Postgres for the database instead of sqllite or MySQL (Tango with Django uses sqllite3, which this author recommended against in a production environment)

Note that the first chapter of this tutorial doesn’t get into creating the full blown-out microblog app yet, but does cover a lot with installation and app file setup.

The downsides? I ran into a couple of issues that took me a while to debug, and I’ll make note of them in more detail below. Also, at the time that this series was made, Django 1.4.3 was the most up-to-date version, so I made sure to install 1.4.3. and not 1.6 or 1.7 — the most up-to-date version as of May 2014.

Issues:

1) When I tried to create a new “vagrant” user in postgres, I got:

ERROR: role “vagrant” already exists

The solution was to run

  1. sudo su postgres
  2. dropuser vagrant

But then I had to make sure to type exit to exit out of postgres@precise64:/vagrant/projects/microblog$ and get back to (blog-venv)vagrant@precise64:/vagrant/projects/microblog$  to continue with the rest of the tutorial.

2) When I ran ‘heroku run python manage.py syncdb’, I got:

Error: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432″?

Luckily, someone on stackoverflow had had the same problem; the solution was to make sure my settings/local.py file was in .gitignore; otherwise, Heroku would be confused by the presence of two DATABASES = { } dictionaries in both base.py and settings.py.

3) Running multiple Django apps in my local environment created PORT conflicts

Since I had been in the middle of working on another Django app from the Tango with Django book when I started following this tutorial, I got a conflict in Vagrant with the port numbers. I ended up having to go into Vagrantfile to change one of the ports from 8888 to 8889.

Screen Shot 2014-05-29 at 3.23.27 PMScreen Shot 2014-05-29 at 3.23.52 PM

 

Instead of being able to see my project in my local browser by just typing $ python manage.py runserver, I had to type python manage.py runserver 0.0.0.0:8000 to see my project in http://127.0.0.1:8889/.

Meanwhile, to see my Tango with Django project, I had to run make sure to specify a local port too: $ python manage.py runserver 0.0.0.0:8887 and http://127.0.0.1:8887/rango.

NOTE: to start working on the project again, follow these steps after getting back into the gswd-vagrant folder:
$ vagrant suspend
$ vagrant up #start the vagrant up again
$ vagrant ssh #password is vagrant
$ source ~/blog-venv/bin/activate

NOTE: if there is a vagrant conflict, make sure to vagrant halt on the other instance of vagrant running.

blog comments powered by Disqus
  • Hi, I'm Linda! I enjoy going to tech meetups, learning web development, and blogging about the learning path. Follow me @LPnotes

Subscribe to The Coding Diaries