1
0
Форкнуть 0
Sample code for the Flask tutorial in the VS Code documentation
Перейти к файлу
Courtney Webster 0e4d14ec63
Adding dev container and updating configs (#95)
* Adding dec container and updating configs

* Update .devcontainer/devcontainer.json
2024-02-27 13:46:56 -08:00
.devcontainer Adding dev container and updating configs (#95) 2024-02-27 13:46:56 -08:00
.github Adding dev container and updating configs (#95) 2024-02-27 13:46:56 -08:00
.vscode Adding dev container and updating configs (#95) 2024-02-27 13:46:56 -08:00
hello_app Add / to routes 2019-02-07 11:47:40 -08:00
.dockerignore Adding docker files 2018-09-25 16:40:52 -07:00
.gitignore Correction 2018-10-17 17:22:46 -07:00
Dockerfile Update Dockerfile (#42) 2021-02-16 16:06:48 -08:00
LICENSE Initial commit 2018-05-14 10:35:23 -07:00
README.md Update README.md 2020-11-20 12:24:47 -07:00
SECURITY.md Microsoft mandatory file 2022-08-30 09:37:23 +00:00
requirements.txt Simplify requirements and update readme 2020-10-26 11:16:24 -07:00
startup.py Update startup.py 2018-10-27 12:56:36 +05:30
startup.txt Adding startup shim for App Service on Linux 2018-10-17 17:04:52 -07:00
test_test1.py Update test_test1.py 2020-05-15 12:31:06 +03:00
uwsgi.ini Adding docker files 2018-09-25 16:40:52 -07:00

README.md

Python/Flask Tutorial for Visual Studio Code

  • This sample contains the completed program from the tutorial, make sure to visit the link: Using Flask in Visual Studio Code. Intermediate steps are not included.

  • It also contains the Dockerfile and uwsgi.ini files necessary to build a container with a production server. The resulting image works both locally and when deployed to Azure App Service. See Deploy Python using Docker containers.

  • To run the app locally:

    1. Run the command cd hello_app, to change into the folder that contains the Flask app.
    2. Run the command set FLASK_APP=webapp (Windows cmd) or FLASK_APP=webapp (macOS/Linux) to point to the app module.
    3. Start the Flask server with flask run.

The startup.py file

In the root folder, the startup.py file is specifically for deploying to Azure App Service on Linux without using a containerized version of the app (that is, deploying the code directly, not as a container).

Because the app code is in its own module in the hello_app folder (which has an __init__.py), trying to start the Gunicorn server within App Service on Linux produces an "Attempted relative import in non-package" error.

The startup.py file, therefore, is a shim to import the app object from the hello_app module, which then allows you to use startup:app in the Gunicorn command line (see startup.txt).

Contributing

Contributions to the sample are welcome. When submitting changes, also consider submitting matching changes to the tutorial, the source file for which is tutorial-flask.md.

Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot automatically determines whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

Additional details