Skip to content

Commit 0dbbd89

Browse files
authored
Update quickstart-python-provider.md
Adding information for Django and Flask
1 parent 1835bd3 commit 0dbbd89

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

articles/azure-app-configuration/quickstart-python-provider.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,32 @@ Add the following key-values to the App Configuration store. For more informatio
171171
message found: True
172172
test.message found: False
173173
```
174+
## Web app usage
175+
You can use Azure App Configuration in your existing python Web Apps by adding the following lines of code into your `settings.py` (For Django) or `app.py` (for Flask) files.
176+
```python
177+
selects = {SettingSelector(key_filter="<your-key-filter>")}
178+
config = load(connection_string=os.environ.get("AZURE_APPCONFIG_CONNECTION_STRING"),
179+
selects=selects,
180+
trim_prefixes=["<prefix-to-trim>"])
181+
```
182+
### Configuration settings in Django
183+
To update individual configuration settings in the Django `settings.py` file, you can reference them from the provider object. e.g.,
184+
```python
185+
MESSAGE = config.get("message")
186+
```
187+
188+
### Configuration settings in Flask
189+
You can update the in-built configuration object in Flask by passing your App Configuration Provider object to the `update` function of your flask app instance in `app.py`:
190+
```python
191+
# NOTE: This will override all existing configuration settings with the same key name.
192+
app.update(config)
193+
194+
# Access a configuration setting directly from within flask configuration
195+
json_value = app.config.get("my_json")
196+
```
197+
198+
199+
Full code samples on how Azure App Configuration is used in python web apps can be found in the [Azure App Configuration Python Samples](https://github.com/Azure/AppConfiguration/tree/main/examples/Python) repo.
174200

175201
## Clean up resources
176202

0 commit comments

Comments
 (0)