title: 【译】在Heroku上部署Django应用(2、部署)
type: categories
date: 2017-05-09 09:57:25
categories: Python
tags: [Heroku, Django]
Heroku支持所有类型的Python应用,包括Django应用。需要说明的是,Django的手动配置很繁琐,最便捷的方法是直接在Heroku控制台生成相对应的应用。
本地服务
执行以下指令,在本地安装相关依赖库。
$ pip install -r requirements.txt
Downloading/unpacking ...
...
Successfully installed Django dj-database-url dj-static django-toolbelt gunicorn psycopg2 static3
Cleaning up...
开启本地服务
$ heroku local web
11:48:19 web.1 | started with pid 36084
11:48:19 web.1 | 2014-07-17 11:48:19 [36084] [INFO] Starting gunicorn 19.0.0
11:48:19 web.1 | 2014-07-17 11:48:19 [36084] [INFO] Listening at: http://0.0.0.0:5000 (36084)
11:48:19 web.1 | 2014-07-17 11:48:19 [36084] [INFO] Using worker: sync
11:48:19 web.1 | 2014-07-17 11:48:19 [36087] [INFO] Booting worker with pid: 36087
最后,一切正常的情况下便可访问http://localhost:5000/
Heroku部署
$ git add .
$ git commit -m "Added a Procfile."
$ heroku login
Enter your Heroku credentials.
...
$ heroku create
Creating intense-falls-9163... done, stack is cedar
http://intense-falls-9163.herokuapp.com/ | git@heroku.com:intense-falls-9163.git
Git remote heroku added
$ git push heroku master
...
-----> Python app detected
...
-----> Launching... done, v7
https://intense-falls-9163.herokuapp.com/ deployed to Heroku
最后执行以下指令,便可在浏览器中打开站点
$ heroku open
原文地址: https://devcenter.heroku.com/articles/deploying-python#django-applications-on-heroku