Python網頁設計:Flask使用筆記(三)- 佈署到Google APP Engine

1.安裝 Cloud SDK

https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe

2.開啟 Cloud SDK Shell

cd 到Flask APP的目錄當中

3.在目錄當中建立 requirements.txt文件

Flask
Werkzeug
gunicorn==19.7.1
#本txt文件可讓APP Engine佈署時,自動安裝套件
#無論是否使用Flask,佈署Python時,gunicorn一定要在requirements.txt當中
--------------------------------------------------------------------或者在CMD使用pip freeze > requirements.txt#產生requirements.txt,但必須於txt中加入gunicorn==19.7.1

4.在目錄當中建立 app.yaml文件

service: default
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3

5.在目錄當中建立 deploy.yaml文件

steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "--project=<your-project-name>"]
timeout: "1600s"

6.檢查目錄中的檔案

#python的檔案一定要是main.py(因為第4步驟$PORT main:app)
#檢查requirements.txt是否有gunicorn==19.7.1
#在本地端運行main.py,檢查是否有任何錯誤
#如果沒任何問題,進行下一步驟

6.佈署到Google APP Engine

在Shell中執行下列指令:gcloud init#進行初始化,依照螢幕上的指令操作即可gcloud app deploy#佈署到APP Engine上#過程中也許會有錯誤產生,這時候就必須針對錯誤到Google搜尋解決方案

7.瀏覽佈署的Flask網站

"專案名稱id".appspot.com

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store