Skip to content

Commit 6839e50

Browse files
committed
Deployment instruction for App Service
1 parent a7e48d9 commit 6839e50

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This one is required if you are deploying to Azure App Service.
2+
POST_BUILD_COMMAND=python manage.py migrate
3+
14
# The following variables are required for the app to run.
25
CLIENT_ID=<client id>
36
CLIENT_SECRET=<client secret>

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ to sign in users and make authenticated calls to the Microsoft Graph API.
3838
You may need to change to a different port to match your redirect_uri setup.
3939
2. Now visit http://localhost:5000
4040

41+
### Deployment
42+
43+
Once you finish testing this web app locally, you can deploy it to your production.
44+
You may choose any web app hosting services you want.
45+
Here we will describe how to deploy it to
46+
[Azure App Service](https://azure.microsoft.com/en-us/products/app-service).
47+
48+
* Follow the ["Quickstart: Deploy a Python (Django or Flask) web app to Azure App Service"](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python),
49+
but replace its sample app (which does not do user sign-in) with this web app.
50+
51+
* [Configure your app's settings](https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#configure-app-settings)
52+
to define
53+
[these environment variables](https://github.com/Azure-Samples/ms-identity-python-webapp-django/blob/main/.env.sample).
54+
4155

4256
## Tutorial
4357

mysite/settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@
3636
# SECURITY WARNING: don't run with debug turned on in production!
3737
DEBUG = True
3838

39-
ALLOWED_HOSTS = []
39+
40+
if os.getenv("WEBSITE_HOSTNAME"): # Settings for Azure App Service,
41+
# See https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#production-settings-for-django-apps
42+
ALLOWED_HOSTS = [os.getenv("WEBSITE_HOSTNAME")]
43+
44+
# See https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#detect-https-session
45+
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
46+
USE_X_FORWARDED_HOST = True
47+
else:
48+
ALLOWED_HOSTS = []
4049

4150

4251
# Application definition

templates/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
<h1>Microsoft Entra ID Django Web App Sample {{version}}</h1>
99
<h2>Welcome {{ user.name }}!</h2>
1010

11-
{% load static %}
12-
<img src="{% static 'topology.png' %}" alt="Topology">
11+
<!-- There is much hussle to get the local static image to show up on App Service.
12+
https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#serve-static-files-for-django-apps
13+
For now, we will use a remote image.
14+
-->
15+
<img src="https://github.com/Azure-Samples/ms-identity-python-webapp-django/raw/main/static/topology.png" alt="Topology">
1316

1417
<ul>
1518
{% if downstream_api %}

0 commit comments

Comments
 (0)