由以下網址安裝Heroku CLI
https://devcenter.heroku.com/articles/heroku-cli
進入虛擬開發環境 (Linux 中建立 Python Django 開發環境 )
$ source tutorial-env/bin/activate
(tutorial-env) $ cd 專案名 ---> 移至專案資料夾內,以下指令都在專案資料夾內執行
確認是否安裝成功
(tutorial-env) $ heroku --version
登入Heroku
(tutorial-env) $ heroku login
修改網站相關設定
(tutorial-env) $ sudo apt-get install libpq-dev python-dev
(tutorial-env) $ pip install dj-database-url dj-static gunicorn psycopg2
(tutorial-env) $ pip freeze > requirements.txt
- 在專案資料夾下建立 runtime.txt 以及 Procfile 檔案,與 requirements.txt 在同一層中 ( 其中 Procfile 的 P 需為大寫 )
runtime.txt 用來指定本網站所使用的Python語言版本
--> python-3.6.4
Procfile 用來讓Heroku知道要從哪裡開始執行指令
--> web: gunicorn TEST.wsgi --log-file -
- 在 settings.py 中修改
# DEBUG = False
# ALLOWED_HOSTS = ['*']
- 並在最底部增加
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- 在 wsgi.py 中修改 (3-19)
# from dj_static import Cling
# application = Cling(get_wsgi_application())
- 定義 .gitignore 檔
# *.pyc
# __pycache__
# staticfiles
上傳網站至Heroku主機
(tutorial-env) $ heroku create 專案名
(tutorial-env) $ git init
(tutorial-env) $ heroku git:remote -a專案名
(tutorial-env) $ git add .
(tutorial-env) $ git commit -m "本次上傳簡介"
(tutorial-env) $ git push heroku master
開始瀏覽自建網站
(tutorial-env) $ heroku open
請先 登入 以發表留言。