A tutorial on deploying the Python Django Framework on the Heroku cloud platform _python

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

Heroku is a great platform, it has a lot of controls, and it's relatively easy to build the environment. In this guide, I will guide you step-by-Step through the deployment of a simple Django application on the Heroku platform
Build a development environment
Heroku tool Chain

Suppose you have registered an account on the Heroku platform and created an application inside, and you need to install the Heroku tool chain for a moment to interact with Heroku via the CLI. In this guide, we use "Sample-project" as the name of the application.
Git warehouse

Before deploying your application to Heroku, you will need to check your code into the GIT repository first. The Git warehouse information provided by Heroku can be found in your application Settings page.

Copy Code code as follows:
One git@heroku.com:sample-project.git

Python and Virtualenv

If this isn't your first Python application, you may have built the environment. Then, there are compatibility issues between the different versions of Pyton, so you should use the VIRTUALENV command to create a virtual environment while developing your Python application.

# Install pip 
$ [sudo] python get-pip.py 
 
# Install virtualenv
$ [sudo] pip Install virtualenv 
 
# Create a V Irtual Environment
$ virtualenv venv
 
# Activate venv
$ source Venv/bin/activate

Create a Django Application

It is recommended 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


deployment of your code

1. Create Procfile
Procfile is used to declare the start Web Dyno command that should be executed. This file should be placed in the manage.py (specified) folder. Simply create a procfile file, as shown in the following line of examples.

Copy Code code as follows:
Unicorn Sample_project.wsgi--log-file-

2. See the short name of the remote server where you want to deploy the code. The following example shows an example of configuring a simple remote server with a short name of origin. You may have configured a lot of remote servers.

$ git Remote-v
Origin 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 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 (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 code you deploy

$ Heroku Open

You should see the standard Django Start page (which is displayed) "It worked! Congratulations on your The django-powered page.

5. Use Dyno to measure your application size

$ heroku Ps:scale web=1
scaling Dynos ... done, now running the Web at 1:1x.

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.