未加星标

Deploying Your Django app on Heroku

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Heroku is a cloud application platform it's a new way of building and deploying web apps, Which makes easy to host your application in the cloud with a simple git push command.

Heroku supports several programming languages like(python, Java,php)

Install the Heroku Toolbelt:

The first thing you need to do is to install the Heroku toolbelt. The toolbelt is a command line software which makes it easy to interact with the Heroku service through your command line.

Here you can find out the Heroku toolbelt installation for Debian/Ubuntu, Run this from your terminal:

wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh

In the below link you need to select your required operating system(Download Heroku Toolbelt for..) for installing heroku toolbelt in your system. And then you can proceed to install.

Please click here

to install Heroku ToolBelt

After successfully installation of toolbelt, you can use the heroku command from your terminal.

heroku login
You will prompt to provide heroku credentials(Email and password), once you have authenticated you can access both heroku and git commands. Create your heroku app:

The following command is used to create an app

heroku create your-app-name

Here 'your-app-name' should be unique, heroku will generate default app-name if you won't specify any app-name.

For creating remote for your app use this command

heroku git:remote -a your-app-name Define a Procfile:

A Procfile is a mechanism for declaring what commands need to run by your application dynos on the Heroku platform.

Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app.

Here first you need to install gunicorn using pip

pip install gunicorn
web: gunicorn yoursettings.wsgi --log-file -

Create new file in the root directory of your application as "app.json"

{
"name": "Your-App-Name",
"description": "Self-hosted app",
"repository": "provide your git repository url",
"scripts": {
"postdeploy": "python manage.py makemigrations && python manage.py migrate"
}
}

"app.json" is a json format file for describing web apps. It declares environment variables, Description, and other information required to run an app on Heroku.

To Load your app Static files you need to use "WhiteNoise", this can be install by using pip

pip install whitenoise

And also you need to update your "wsgi.py" file too

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

Update STATIC_ROOT in your "settings.py" file for loading your static files

STATIC_ROOT = (os.path.join(BASE_DIR, "static")) Database Configuration:

For configuring your database, First you need to install "dj_database_url" using pip

pip install dj_database_url
pip install psycopg2
import dj_database_url
DATABASES = {
'default': dj_database_url.config(
default='sqlite:////{0}'.format(os.path.join(BASE_DIR, 'db.sqlite3'))
)
} Dependecies used: 1. dj-database-url
2. Django
3. gunicorn
4. psycopg2
5. whitenoise

Update all your app dependencies in your "requirements.txt" file which is in the root directory of your app. These are the basic dependencies used.

Deploying Your app on Heroku:

This can be done by using simple git command

* It will read yourDjango appication

* Install your requirements provided

* Detects your Procfile

* It will collect your static files.

git push heroku master

After Sucessfully deploying your app, you will be provided with the url to open your app.

you can also run it by using the command.

heroku open

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: DjangoJavaDebianUbuntuPHPTIPython
分页:12
转载请注明
本文标题:Deploying Your Django app on Heroku
本站链接:http://www.codesec.net/view/532584.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(19)