接续着昨天的进度,首先可以先準备你的程式,而我在github 上有放上範例:
https://github.com/wilsonsujames/AppEngineDeploy/tree/master/APP_Engine_deploy
可以发现主程式为main.py,假设你有一些html页面,放在templates,但是又不希望templates资料夹的名称叫做
templates,可以在建立Flask物件时,这样设定:
template_dir = os.path.abspath('./public')app = Flask(__name__,template_folder=template_dir)
再来可以看到app.yaml:
runtime: python38handlers: - url: /static static_dir: static - url: /.* secure: always redirect_http_response_code: 301 script: auto
可以发现使用的python版本为3.8,
设定了static路径,
所有的路径都要由HTTPs来通过,没有的话报301代码错误。
更详细的设定介绍,可以参考官网的攻略:
https://cloud.google.com/appengine/docs/standard/python3/config/appref
可以从中发现,跨域请求(cors)也可以在这里做设定。
而如果你希望有一个API定期的被呼叫呢?
那可以设定cron.yaml:
https://cloud.google.com/appengine/docs/standard/python3/scheduling-jobs-with-cron-yaml
在requirements.txt中新增需要的套件:
Flaskgoogle-cloud-storage
完成之后可以打开昨天的Google sdk,将路径cd到有yaml设定党的地方打上
gcloud app deploy
确认完之后等待结果,而可以使用
gcloud app browse
来确认执行结果。
假设有错误的话,也可以由这里来寻找错误: