Deploy Django applications on Heroku
Heroku is a great platform with many controls, and it is relatively easy to build an environment. In this guide, I will step by step guide you to deploy a simple Django application on the Heroku platform.
Build a development environment Heroku tool chain
Assume that you have registered an account on the Heroku platform and created an application in it. To later interact with Heroku through CLI, you need to install Heroku toolchain. In this guide, we use "Sample-Project" as the application name.
Git Repository
Before deploying your application to Heroku, you must first check your code into the git repository. The git Repository Information provided by Heroku can be found on your application settings page.
Git clone git@heroku.com: sample-project.git
Python and Virtualenv
If this is not your first python application, you may have set up the environment. Then, there are compatibility issues between different Pyton versions. Therefore, you should use the Virtualenv command to create a virtual environment when developing your Python application.
# Install pip
$ [Sudo] python get-pip.py
# Install Virtualenv
$ [Sudo] pip install virtualenv
# Create a virtual environment
$ Virtualenv venv
# Activate venv
$ Source venv/bin/activate
Create a Django Application
We recommend that you install django-toolbelt, which consists of the following parts.
-Django
-Gunicorn (WSGI server)
-Dj-database-url (A Django Configuration tool)
-Dj-static (A Django static file server)
(Venv) $ pip install django-toolbelt
(Venv) $ cd Sample-Project
# Create a Django project name Sample_Project
# A valid Django project name can't contain dash
(Venv) $ django-admin.py startproject Sample_Project.
# Create the requirements file
(Venv) $ pip freeze> requirements.txt
Deploy your code
1. Create ProcFile
ProcFile is used to declare the starting web dyno command to be executed. This file should be placed in the manage. py (specified) folder. Create a ProcFile file, as shown in the following example.
Web: gunicorn Sample_Project.wsgi -- log-file-
2. Check the remote server name for which you want to deploy the code. The following example shows an example of configuring only one simple remote server, which is abbreviated as origin. (Hypothesis) You may have configured many remote servers.
$ Git remote-v
Origin git@heroku.com: Sample-Project.git)
Origin git@heroku.com: Sample-Project.git (push)
3. Deploy your code
Use git push to deploy your code.
$ Git push origin master
Initializing repository, done.
Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (11/11), 2.64 KiB | 0 bytes/s, done.
Total 11 (delta 0), reused 0 (delta 0)
-----> Python app detected
-----> Installing runtime (python-2.7.8)
-----> Installing dependencies with pip
Downloading/unpacking Django = 1.6.6 (from-r requirements.txt (line 1 ))
Downloading/unpacking dj-database-url = 0.3.0 (from-r requirements.txt (line 2 ))
Downloading dj_database_url-0.3.0-py2.py3-none-any.whl
Downloading/unpacking dj-static = 0.0.6 (from-r requirements.txt (line 3 ))
Downloading dj-static-0.0.6.tar.gz
...
Git@heroku.com: Sample-Project.git
* [New branch] master-> master
4. Verify the deployed code
$ Heroku open
You should see the standard Django start page (displayed) "It worked! Congratulations on your first Django-powered page ."
5. Use dyno to measure your application scale
$ Heroku ps: scale web = 1
Scaling dynos... done, now running web at 1: 1X.
Install Nginx + uWSGI + Django on Ubuntu Server 12.04
Django tutorial
Build a Django Python MySQL Linux development environment
Django details: click here
Django's: click here
This article permanently updates the link address: