2: Prepare your app for deployment to Azure App Service
In this article, you prepare an app to deploy to the Azure App Service for this tutorial. You can use an existing app or create or download an app.
If you already have an app that you'd like to work with, make sure you have a requirements.txt file that describes your dependencies, including frameworks like Flask or Django. You can use any framework of your choosing.
If you don't already have an app, use one of the options below. Be sure to verify that the app runs locally.
Option 1: VS Code Flask tutorial sample
Download or clone https://github.com/Microsoft/python-sample-vscode-flask-tutorial, which is the result of following the Flask Tutorial.
Option 2: VS Code Django tutorial sample
Download or clone https://github.com/Microsoft/python-sample-vscode-django-tutorial, which is the result of following the Django Tutorial.
If your Django app uses a local SQLite database like this sample, you need to include a pre-initialized and pre-populated copy of the db.sqlite3 file in your repository. The reason for this is that, at present, App Service for Linux doesn't have a means to run Django's
migrate command as part of deployment, so you must deploy a pre-made database. Even then, the database is effectively read-only; writing to the database also causes errors.
The best option in any case is to use a separate database that's deployed and initialized independently from the app code.
Option 3: Create a minimal Flask app
This section describes the minimal Flask app used in this walkthrough.
Create a new folder, open it in VS Code, and add a file named hello.py with the contents below. The app object is purposely named
myappto demonstrate how the names are used in the startup command for the App Service, as you learn later.
from flask import Flask myapp = Flask(__name__) @myapp.route("/") def hello(): return "Hello Flask, on Azure App Service for Linux"
Create a file named requirements.txt with the following contents:
Open a terminal using the menu command Terminal > New Terminal.
In the terminal, create and activate a virtual environment named
Install the app's dependencies:
pip install -r requirements.txt
Set a FLASK_APP environment variable tells Flask where to find the app object:
Run the app:
You can then open the app in a browser using the URL