Search code examples
azureflaskweb-applicationsazure-web-app-serviceazure-webapps

Azure flask app deployed always shows the default landing page


I have deployed a simple Flask application on an azure webapp by forking the repo from https://github.com/Azure-Samples/python-docs-hello-world

Here is my application.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"


@app.route("/sms")
def hello_sms():
    return "Hello World SMS!"


# if __name__ == '__main__':
#    app.run(debug = True)

And this is my requirements.txt

click==6.7
Flask==1.0.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
Werkzeug==0.14.1

At first when I opened the URL ( https://staysafe.azurewebsites.net/ ) i got this message, "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." After which i when to the application settings in the webapp dashboard in azure and set a python version. And ever since this is what I get when i open my URL open url

Any clue as to what is going wrong?


Solution

  • Seams that your code is not uploaded to portal.

    Please follow this official document for your test.

    I Used your code from https://github.com/Azure-Samples/python-docs-hello-world, and works fine. The steps as below:

    Environment: python3.7, windows 10

    1.Open git bash,download the code to local using git clone https://github.com/Azure-Samples/python-docs-hello-world.git

    2.In git bash, execute cd python-docs-hello-world

    3.In git bash, execute following command one by one:

    py -3 -m venv venv
    venv/scripts/activate
    pip install -r requirements.txt
    FLASK_APP=application.py flask run
    

    4.Open a web browser, and navigate to the sample app at http://localhost:5000/ .

    It is to make sure it can work well in local.

    5.Then just follow the article to create deployment credetial / resource group / service plan / a web app

    6.If no issues, in git bash, push the code to azure:

    git remote add azure <deploymentLocalGitUrl-from-create-step>
    

    Then execute git push azure master

    7.Browse to the website like https://your_app_name.azurewebsites.net, or https://your_app_name.azurewebsites.net/sms,

    it works fine, screenshot as below: enter image description here