Skip to content

Commit 1f45bac

Browse files
Merge pull request #209010 from JasonFreeberg/patch-123
Add info on serving static files with Flask
2 parents 201924e + 833a063 commit 1f45bac

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

articles/app-service/configure-language-python.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ For App Service, you then make the following modifications:
179179
]
180180
```
181181
182+
## Serve static files for Flask apps
183+
184+
If your Flask web app includes static front-end files, first follow the instructions on [managing static files](https://flask.palletsprojects.com/en/2.1.x/tutorial/static/) in the Flask documentation. For an example of serving static files in a Flask application, see the [quickstart sample Flask application](https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart) on Github.
185+
186+
To serve static files directly from a route on your application, you can use the [`send_from_directory`](https://flask.palletsprojects.com/en/2.2.x/api/#flask.send_from_directory) method:
187+
188+
```python
189+
from flask import send_from_directory
190+
191+
@app.route('/reports/<path:path>')
192+
def send_report(path):
193+
return send_from_directory('reports', path)
194+
```
195+
182196
## Container characteristics
183197

184198
When deployed to App Service, Python apps run within a Linux Docker container that's defined in the [App Service Python GitHub repository](https://github.com/Azure-App-Service/python). You can find the image configurations inside the version-specific directories.

0 commit comments

Comments
 (0)