简体   繁体   English

在 Google App Engine 中部署 FLASK 应用程序时从 app.py 更改为 main.py

[英]Change from app.py to main.py when deploying a FLASK app in Google App Engine

I am following the instructions here to deploy an app in Google App Engine.我正在按照此处的说明在 Google App Engine 中部署应用程序。 Everything works correctly.一切正常。

Nevertheless, Google, by default, looks for the main folder (where app = Flask(__name__) is defined) in main.py .然而,默认情况下,Google 会在 main.py 中查找主文件夹(其中定义了app = Flask(__name__) main.py How could I redefine this?我怎么能重新定义这个? I would like to define this main folder as app.py .我想将此主文件夹定义为app.py

  1. Rename main.py to app.pymain.py重命名为app.py

  2. Add entrypoint: gunicorn -b :$PORT app:app to your app.yaml file.entrypoint: gunicorn -b :$PORT app:app添加到您的app.yaml文件中。 This is where you are telling Google to find the app object in a file called app这是您告诉 Google 在名为app的文件中查找app对象的地方

  3. Add gunicorn to your requirements.txt filegunicorn添加到您的requirements.txt文件中

Notes:笔记:

i.一世。 Because you're changing from main.py to app.py , you need to specify an entrypoint.因为您要从main.py更改为app.py ,所以您需要指定一个入口点。 GAE documentation says GAE 文档

If your app meets the following requirements, App Engine will start your app with the gunicorn web server if you don't specify the entrypoint field:如果您的应用满足以下要求,且您未指定入口点字段,App Engine 将使用 gunicorn Web 服务器启动您的应用:

  • The root of your app directory contains a main.py file with a WSGI-compatible object called app. app 目录的根目录包含一个 main.py 文件,其中包含一个名为 app 的 WSGI 兼容对象。

  • Your app does not contain Pipfile or Pipfile.lock files.您的应用不包含 Pipfile 或 Pipfile.lock 文件。

ii. ii. If you add an entrypoint, then you need to include gunicorn in your requirements.txt file如果添加入口点,则需要在 requirements.txt 文件中包含gunicorn

iii. iii. I just tested the above configuration (the answer I gave) on a dev environment (Python 3.9 environment on Macbook using dev_appserver.py) and it works我刚刚在开发环境(Macbook 上使用 dev_appserver.py 的 Python 3.9 环境)上测试了上述配置(我给出的答案)并且它可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM