Tutorial on deploying Python Django framework on Heroku cloud platform, herokudjango

Source: Internet
Author: User
Tags install django pip install django virtualenv

Tutorial on deploying Python Django framework on Heroku cloud platform, herokudjango

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.
 
Copy codeThe Code is as follows: one 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.

Copy codeThe Code is as follows: unicorn 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 -vorigin git@heroku.com:Sample-Project.git (fetch)origin git@heroku.com:Sample-Project.git (push)

3. Deploy your code

Use git push to deploy your code.
 

$ git push origin masterInitializing 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...To 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=1Scaling dynos... done, now running web at 1:1X.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.