April 18, 2012

#

Deploying Django app on Heroku platform

Before using Heroku , I used Django-nonrel with Appengine , Django-Appengine , Google Appenigne , FluxFlex , Gondor hosting and Alwaysdata . From my knowledge I think Django-app deployment on Heroku is easier than others . When I was following official tutorial of django app deployment on Heroku , I got some errors so I googled and fixed all those errors . This is Heroku's official Documentation .Deploy Djang on heroku . Lets Start 
Install Heroku-toolbelt
wget -qO- https://toolbelt.heroku.com/install.sh | sh
1.Create folder called Heroku and move into it . $ mkdir Heroku && cd Heroku
2. Create a virtualenv and Activate your virtual environment
$ virtualenv --no-site-packages venv $ source venv/bin/activate This will change your prompt to include the project name. (You must source the virtualenv environment for each terminal session where you wish to run your app.)
3. Install dependencies with pip: $ pip install Django psycopg2 This step was failed for me , During Installation of "pip install psycopg" I got "Error: pg_config executable not found."
Linux User(debian based) : Make sure that u have "libpq-dev python-dev " packages installed . I used following command to install the above libraries $ sudo apt-get install libpq-dev python-dev for Windows User click here :
4.Great job ! Now Its time to create a Django app in the current directory: $ django-admin.py startproject greetingheroku .
5. Test the app runs locally by starting up the Django development webserver: $ python manage.py runserver
6. Create a pip requirements file which declares our required Python modules: $ pip freeze > requirements.txt All packages required should be declared explicitly in requirements.txt:
  $ nano requirements.txt
    Django==1.4
    psycopg2==2.4.5
now type ctrl+o(save) and ctrl+x(exit)
7. Commit to Git create .gitignore file and Exclude Virtualenv , because we don't want to push our local envirnment to heroku :
  $ nano .gitignore
    venv
    *.pyc
use ctrl+o(save) & ctrl+x(exit) . You will use Git to deploy code to Heroku
8. Initialize a Git repo and commit the project (if you aren’t already tracking your project with Git):
  $ git init
    Initialized empty Git repository in /home/ashish/developer/Heroku/greetingheroku/.git/
  $ git add .
  $ git commit -m "my django app" 
  $ heroku keys:add

9. Deploy to Heroku Create an app on the Cedar stack:
  $ heroku create --stack cedar
    Creating simple-spring-9999... done, stack is cedar
    http://simple-spring-9999.herokuapp.com/ | git@heroku.com:simple-spring-9999.git
    Git remote heroku added

10. Deploy your app: $ git push heroku master If "git push heroku master" gives you an error something like "heroku does not appear to be a git repository ." Then run the following command to add heroku as a git repository . Mostly this will happen , when u changed your app name from "Heroku dev center " $ git remote add heroku git@heroku.com:your-app-name.git
11. Check to see that your web process is up, to start $ heroku ps View your logs: $ heroku logs
12. finally visit your app on the web. $ heroku open
13. Syncing Database $ heroku run python manage.py syncdb 14. Using Django Shell $ heroku run python manage.py shell
For more information please visit > Deploy Djang on heroku .
My heroku app dotorbit.herokuapp.com

1 comment:

  1. Solving Heroku Error H14 with Django

    1 : nano Procfile
    add following line ,
    "web: python website/manage.py runserver 0.0.0.0:$PORT"

    2 : git push heroku master
    3 : heroku ps:scale web=1

    Bingo !!

    ReplyDelete

Follow Us @soratemplates