You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Deploy a Python (Flask) web app with PostgreSQL in Azure
2
2
3
-
This is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service. The Flask app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorial [*Deploy a Python (Django or Flask) web app with PostgreSQL in Azure*](https://docs.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app) or by using the [Azure Developer CLI (azd)](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/overview) according to the instructions below.
3
+
This is a Python web app using the Flask framework and the Azure Database for PostgreSQL relational database service. The Flask app is hosted in a fully managed Azure App Service. This app is designed to be be run locally and then deployed to Azure. You can either deploy this project by following the tutorial [*Deploy a Python (Django or Flask) web app with PostgreSQL in Azure*](https://docs.microsoft.com/azure/app-service/tutorial-python-postgresql-app) or by using the [Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) according to the instructions below.
4
4
5
5
## Requirements
6
6
@@ -16,41 +16,40 @@ The [requirements.txt](./requirements.txt) has the following packages:
16
16
|[python-dotenv](https://pypi.org/project/python-dotenv/)| Read key-value pairs from .env file and set them as environment variables. In this sample app, those variables describe how to connect to the database locally. <br><br> Flask's [dotenv support](https://flask.palletsprojects.com/en/2.1.x/cli/#environment-variables-from-dotenv) sets environment variables automatically from an `.env` file. |
17
17
|[flask_wtf](https://pypi.org/project/Flask-WTF/)| Form rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension. |
18
18
19
-
20
19
## Using this project with the Azure Developer CLI (azd)
21
20
22
-
This project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/overview),
21
+
This project is designed to work well with the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview),
23
22
which makes it easier to develop apps locally, deploy them to Azure, and monitor them.
24
23
25
24
### Local development
26
25
27
-
This project has devcontainer support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension.
26
+
This project has devcontainer support, so you can open it in Github Codespaces or local VS Code with the Dev Containers extension.
28
27
29
28
🎥 [Watch a screencast of running the app in Github Codespaces.](https://www.youtube.com/watch?v=r6Hnp9RXUpY)
30
29
31
-
Steps for running the server:
30
+
Steps for running the server:
32
31
33
32
1. (Optional) If you're unable to open the devcontainer, [create a Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate that.
34
33
35
34
2. Install the requirements:
36
35
37
-
```shell
38
-
pip install -r requirements.txt
39
-
```
36
+
```shell
37
+
pip install -r requirements.txt
38
+
```
40
39
41
40
3. Create an `.env` file using `.env.sample` as a guide. Set the value of `DBNAME` to the name of an existing database in your local PostgreSQL instance. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate foryour local PostgreSQL instance. If you'rein the devcontainer, copy the values from `.env.sample.devcontainer`.
42
41
43
42
4. Run the migrations:
44
43
45
-
```shell
46
-
flask db upgrade
47
-
```
44
+
```shell
45
+
flask db upgrade
46
+
```
48
47
49
48
5. Run the local server: (or use VS Code "Run" button and select"Run server")
50
49
51
-
```shell
52
-
flask run
53
-
```
50
+
```shell
51
+
flask run
52
+
```
54
53
55
54
### Deployment
56
55
@@ -64,21 +63,21 @@ Steps for deployment:
64
63
2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you opened this repository in a devcontainer, that part will be done for you.)
65
64
3. Provision and deploy all the resources:
66
65
67
-
```shell
68
-
azd up
69
-
```
66
+
```shell
67
+
azd up
68
+
```
70
69
71
-
It will prompt you to login and to provide a name (like "flask-app") and location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there are availability constraints for some of the resources.
70
+
It will prompt you to login and to provide a name (like "flask-app") and location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there are availability constraints for some of the resources.
72
71
73
72
4. When `azd` has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the restaurant review app! 🎉 If you see an error, open the Azure Portal from the URL in the command output, navigate to the App Service, select Logstream, and check the logs for any errors.
74
73
75
-

74
+

76
75
77
76
5. When you've made any changes to the app code, you can just run:
78
77
79
-
```shell
80
-
azd deploy
81
-
```
78
+
```shell
79
+
azd deploy
80
+
```
82
81
83
82
### CI/CD pipeline
84
83
@@ -101,4 +100,4 @@ azd monitor --overview
101
100
102
101
## Getting help
103
102
104
-
If you're working with this project and running into issues, please post in [Discussions](/discussions).
103
+
If you're working with this project and running into issues, please post in [Issues](/issues).
0 commit comments