Django+Heroku is an awesome cuisine!
For long I thought heroku is the den built specifically for ruby programmers. Looks like the landscape is changing! Now Djangoer's can peep into the Heroku stack with a wry smile and enjoy the fruits of their work.Today, I am interested in sharing what I learned while deploying my test app to heroku cedar stack.
- A bit of basic python knowledge helps a long way.
- You should have a working Django based application.
- You got to create a file named requirements.txt in your parent directory with all the required software details.
- testapp will reside in a directory testapp/testapp, and requirements.txt has to be placed in the parent testapp directory.
- Create a virtualenv within your application directory by typing $ virtualenv venv --distributable
- Run the command pip intall -r requirements.txt
- My requirements.txt looks have the following content,
Django==1.4.1 South psycopg2==2.4.5 dj-database-url==0.2.0 Flask==0.9
Add all the files to git. ( so a github account is essential, if you wannabe a good social coder.)
$git init $git add . $git commit -m "commits" ( if you dont have git configured on your system, the above commands wont work well) $git push
- Push your application to the heroku stack $ git push heroku master
- Run your server using heroku South $heroku run python manage.py/runserver
- SyncDB before opening the website. Here is the catch, you got to setup your postgres DB instance on heroku. You can do that by login to https://postgres.heroku.com . NO PAYMENTS, but they might take your credit card details for account verification, but no charges.I found this a bit annoying, if I am not charged then why the heck do I have to give away my Credit card details.I am just testing the stuff dude. Anyway, the end result is good, so no cribbing. Heroku, will give you the DATABASE details to be pasted in your settings.py file, it will look something like this,
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'd32333645f', 'HOST': 'asdasasdasdasd.compute-1.amazonaws.com', 'PORT': 5432, 'USER': 'asdasdasdasda', 'PASSWORD': 'ASADSADSADASDASDASD' } }
- Once you paste the above details to your settings.py , add the files to git again and then push master branch to heroku stack.This will keep heroku up to date.
- Run heroku run python manage.py syncdb , this will set up your DB on heroku stack.
- See your cool website by typing in heroku open
- Enjoy django development on heroku.