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.
- Get your Django project code.
-
Create a virtualenv with a no-site-packages command ::
virtualenv vent --no-site-packages
-
Install Django, psycopg2 (postgres connector), gunicorn and any other required Django libraries.
- Confirm that you have all the required libraries and you can run your code locally using
manage.py runserver. -
Create a requirement.txt by using ::
pip freeze > requirements.txt
-
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.
-
Create a Procfile. Put this entry: ::
web: python mysite/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3shabda
-
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]
-
(If you aren't tracking your files with git yet.) Track your files with git. ::
git init git add . git commit -am "First commit"
-
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
-
Authenticate to heroku with
::
heroku auth:login
-
Run this command. ::
heroku create --stack cedar
This will create a new Heroku app and create a new remote in your git repo.
-
Push your code to heroku. ::
git push heroku master
-
Your app should be working on Heroku now.
heroku openwill show your site.
Related Posts
- Two Scoops of Django: Review
- Serving static files in Django
- Logging in Django
- Common testing scenarios for Django app.
- Deploying django using docker
Can we help you build amazing apps? Contact us today.
Good tips learned a lot and it is so useful for me.