Skip to content

Latest commit

 

History

History

python-django-webapp-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Sample Python Django Application using Azure App Configuration

This is the sample Django application that uses the Azure App Configuration Service Deploy a Python (Django or Flask) web app to Azure App Service. For instructions on how to create the Azure resources and deploy the application to Azure, refer to the Quickstart article.

A sample Flask application is also available.

If you need an Azure account, you can create one for free.

Prerequisites

You must have an Azure subscription, and a Configuration Store to use this package.

To create a Configuration Store, you can either use Azure Portal or if you are using Azure CLI you can simply run the following snippet in your console:

az appconfig create --name <config-store-name> --resource-group <resource-group-name> --location eastus

Create Keys

az appconfig kv set --name <config-store-name> --key testapp_settings_message --value "Hello from Azure App Configuration"
az appconfig kv set --name <config-store-name> --key testapp_settings_font_size --value "30px"
az appconfig kv set --name <config-store-name> --key testapp_settings_color --value "azure"
az appconfig kv set --name <config-store-name> --key sentinel --value "1"
az appconfig feature set --name <config-store-name> --feature Beta

Create Key Vault Reference

Requires Key Vault with Secret already created.

az appconfig kv set-keyvault --name <config-store-name> --key secret_key --secret-identifier <key-vault-reference>

Setup

Install the Azure App Configuration Provider client library for Python and other dependencies with pip:

pip install -r requirements.txt

Set your App Configuration store endpoint as an environment variable.

Command Prompt

setx AZURE_APPCONFIG_ENDPOINT "your-store-endpoint"

PowerShell

$Env:AZURE_APPCONFIG_ENDPOINT="your-store-endpoint"

Linux/ MacOS

export AZURE_APPCONFIG_ENDPOINT="your-store-enpoint"

Start the django application using the following command:

# Run database migration
python manage.py migrate
# Run the app at http://127.0.0.1:8000
python manage.py runserver

Refresh Configuration

To refresh your configuration, you first update the value in Azure App Configuration, then update the Sentinel value to trigger a refresh.

az appconfig kv set --name <config-store-name> --key testapp_settings_color --value "violet"
az appconfig kv set --name <config-store-name> --key sentinel --value "2"
az appconfig feature enable --name <config-store-name> --feature Beta

Refresh the page in your browser to see the updated value.

NOTE: By default refresh can only be triggered every 30 seconds. You might have to wait up to 30 seconds and refresh the page again in order to see a change.