Deploying Django apps on Heroku

By : Shabda Raaj

Deploying Django apps on Heroku:

Read this first: http://devcenter.heroku.com/articles/django.

This is a great article by the Heroku. I am just filling in some more details and making this step-by-step.

  1. Get your Django project code.
  2. Create a virtualenv with a no-site-packages command ::

    virtualenv vent --no-site-packages

  3. Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.

  4. Confirm that you have all the required libraries and you can run your code locally using manage.py runserver.
  5. Create a requirement.txt by using ::

    pip freeze > requirements.txt
    
  6. Make sure you have a requirements.txt at the root of your repo. Heroku uses this to identify that the app is a Python app.

  7. Create a Procfile. Put this entry: ::

    web: python mysite/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3shabda

  8. This is what your directory structure will look like

    ::

    [root-of-heroku-folder]
        requirements.txt
        Procfile
        [Django-project-folder]
            __init__.py
            manage.py
            settings.py
            [app1]
            [app2]
    
  9. (If you aren't tracking your files with git yet.) Track your files with git. ::

    git init git add . git commit -am "First commit"

  10. Make sure you have the heroku toolbelt installed. If not go to http://toolbelt.herokuapp.com/ and install.

11.You should have these commands available now: ::

heroku
foreman
  1. Authenticate to heroku with

    ::

    heroku auth:login
    
  2. Run this command. ::

    heroku create --stack cedar
    

This will create a new Heroku app and create a new remote in your git repo.

  1. Push your code to heroku. ::

    git push heroku master
    
  2. Your app should be working on Heroku now. heroku open will show your site.


Related Posts


Can we help you build amazing apps? Contact us today.

Topics : django

Comments

imraanafridi@gmail.com

Good tips learned a lot and it is so useful for me.

commmenttor
pritesh 24th April, 2012

hello

i am looking on help regarding deployment process,i want to hide the source code at deployment server for django applications so that only compile code copied at server.

so please provide me help on this

thanks

commmenttor
somnath 26th Nov., 2012

i have follow same process but getting error like

$ git push heroku master
Counting objects: 55, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (53/53), done.
Writing objects: 100% (55/55), 22.23 KiB, done.
Total 55 (delta 5), reused 0 (delta 0)

-----> Heroku receiving push
! Heroku push rejected, no Cedar-supported app detected

To git@heroku.com:lit-peak-2747.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:lit-peak-2747.git'
please help me where i'm missing things

commmenttor
Ryan Liao

Hi somnath ,

You probably forgot to add the Procfile or the requirements.txt file.

Thanks,
Ryan

commmenttor
burberry online espaċ¸½a

Battle suits as well as as with every parts give peace because of wetness their the wicking, Lightweight and

commmenttor
© Agiliq, 2009-2012