Python 应用无法从 Azure 应用服务访问

Python app not able to access from azure app services

我已经通过 Visual Studio 代码将 Python 应用部署到 Azure 应用服务(OS:Linux,Python)。我可以看到 wwwroot 文件夹和应用程序服务中的文件,但是当我尝试通过 URL 访问应用程序服务时,登录页面未显示。请参考以下代码:

from flask import *

app=Flask(__name__)

@app.route('/')
def welcome():
    return render_template("login_post.html")

"""using POST request method"""
@app.route('/login',methods=["POST"])
def login():
    uname=request.form["uname"]
    password=request.form["pass"]

    if uname=="shannu" and password=="guru":
        return "Welcome %s"%uname
    
if __name__=='__main__':
    app.run()

wwwroot文件夹下的文件(在应用服务中)参考截图:
Index of /wwwroot/ directory

不确定我在这里遗漏了什么。提前致谢。

您需要添加启动命令。

gunicorn --bind=0.0.0.0 --timeout 600 app:app

官方文档:

Flask app--Startup command

建议

如果此命令对您没有用,建议您通过 vscode 部署您的 Flask 应用程序。

您会发现 azure web 应用程序会自动为 'app:app' 生成 gunicorn 命令。