A tutorial on deploying Python's Django Framework on the Heroku cloud Platform

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 the environment is relatively easy to build. In this guide, I'll walk you through the deployment of a simple Django application on the Heroku platform
Build the development environment
Heroku tool Chain

Let's say you've already registered an account on the Heroku platform and created an app in it that you need to install the Heroku toolchain for a while to interact with Heroku through the CLI. In this guide, we use "Sample-project" as the name of the application.
Git repository

Before you deploy your app to Heroku, you need to check your code into the GIT repository first. The Git repository information provided by Heroku can be found in your app settings page.

Copy the Code code as follows:

One git@heroku.com:sample-project.git

Python and Virtualenv

If this is not your first Python app, you may have set up the environment. Then there are compatibility issues between the different Pyton versions, so you should use the VIRTUALENV command to create a virtual environment when developing your Python app.

# install PIP $ [sudo] python get-pip.py  # install virtualenv$ [sudo] pip Install virtualenv  # Create a virtual en vironment$ virtualenv venv # Activate venv$ Source Venv/bin/activate

Create a Django App

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


Deploy 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 example.

Copy the Code code as follows:

Unicorn Sample_project.wsgi--log-file-

2. Review the remote server abbreviation for which you want to deploy the code. The following example shows an example of configuring only a simple remote server, which is referred to as Origin. (suppose) You may have configured a lot of 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 One (delta 0), reused 0 (delta 0)-----> Python App detected-----> Installing runtime (python-2.7.8)-----> I nstalling 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-and master

4. Verify the code you deployed

$ Heroku Open

You should see the standard Django Start page (shown as) "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.