Skip to content

Commit 985f8b2

Browse files
authored
Merge pull request #23 from pamelafox/readme-str
Fix readme, str, devcontainer.json
2 parents e8ad1fd + 9175465 commit 985f8b2

File tree

3 files changed

+71
-68
lines changed

3 files changed

+71
-68
lines changed

.devcontainer/devcontainer.json

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,56 @@
33
"dockerComposeFile": "docker-compose.yml",
44
"service": "app",
55
"workspaceFolder": "/workspace",
6-
"settings": {
7-
"sqltools.connections": [
8-
{
9-
"name": "Container database",
10-
"driver": "PostgreSQL",
11-
"previewLimit": 50,
12-
"server": "localhost",
13-
"port": 5432,
14-
"database": "app",
15-
"username": "app_user",
16-
"password": "app_password"
17-
}
18-
],
19-
"python.pythonPath": "/usr/local/bin/python",
20-
"python.languageServer": "Pylance",
21-
"python.linting.enabled": true,
22-
"python.linting.mypyEnabled": true,
23-
"python.testing.pytestEnabled": true,
24-
"python.formatting.provider": "black",
25-
"python.formatting.blackArgs": [
26-
"--line-length=80"
27-
],
28-
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
29-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
30-
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
31-
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
32-
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
33-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
34-
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
35-
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
36-
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
37-
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
38-
},
396
"features": {
407
"ghcr.io/devcontainers/features/github-cli:1": {
41-
"version": "latest"
42-
}
43-
},
44-
// Add the IDs of extensions you want installed when the container is created.
45-
"extensions": [
46-
"ms-azuretools.azure-dev",
47-
"ms-python.python",
48-
"ms-python.vscode-pylance",
49-
"mtxr.sqltools",
50-
"mtxr.sqltools-driver-pg"
51-
],
8+
"version": "latest"
9+
}
10+
},
11+
"customizations": {
12+
"vscode": {
13+
// Add the IDs of extensions you want installed when the container is created.
14+
"extensions": [
15+
"ms-azuretools.azure-dev",
16+
"ms-python.python",
17+
"ms-python.vscode-pylance",
18+
"mtxr.sqltools",
19+
"mtxr.sqltools-driver-pg"
20+
],
21+
"settings": {
22+
"sqltools.connections": [
23+
{
24+
"name": "Container database",
25+
"driver": "PostgreSQL",
26+
"previewLimit": 50,
27+
"server": "localhost",
28+
"port": 5432,
29+
"database": "app",
30+
"username": "app_user",
31+
"password": "app_password"
32+
}
33+
],
34+
"python.pythonPath": "/usr/local/bin/python",
35+
"python.languageServer": "Pylance",
36+
"python.linting.enabled": true,
37+
"python.linting.mypyEnabled": true,
38+
"python.testing.pytestEnabled": true,
39+
"python.formatting.provider": "black",
40+
"python.formatting.blackArgs": [
41+
"--line-length=80"
42+
],
43+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
44+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
45+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
46+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
47+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
48+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
49+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
50+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
51+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
52+
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
53+
}
54+
}
55+
},
5256
// Use 'forwardPorts' to make a list of ports inside the container available locally.
5357
"forwardPorts": [
5458
5000, 5432

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Deploy a Python (Flask) web app with PostgreSQL in Azure
22

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.
44

55
## Requirements
66

@@ -16,41 +16,40 @@ The [requirements.txt](./requirements.txt) has the following packages:
1616
| [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. |
1717
| [flask_wtf](https://pypi.org/project/Flask-WTF/) | Form rendering, validation, and CSRF protection for Flask with WTForms. Uses CSRFProtect extension. |
1818

19-
2019
## Using this project with the Azure Developer CLI (azd)
2120

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),
2322
which makes it easier to develop apps locally, deploy them to Azure, and monitor them.
2423

2524
### Local development
2625

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.
2827

2928
🎥 [Watch a screencast of running the app in Github Codespaces.](https://www.youtube.com/watch?v=r6Hnp9RXUpY)
3029

31-
Steps for running the server:
30+
Steps for running the server:
3231

3332
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.
3433

3534
2. Install the requirements:
3635

37-
```shell
38-
pip install -r requirements.txt
39-
```
36+
```shell
37+
pip install -r requirements.txt
38+
```
4039

4140
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 for your local PostgreSQL instance. If you're in the devcontainer, copy the values from `.env.sample.devcontainer`.
4241

4342
4. Run the migrations:
4443

45-
```shell
46-
flask db upgrade
47-
```
44+
```shell
45+
flask db upgrade
46+
```
4847

4948
5. Run the local server: (or use VS Code "Run" button and select "Run server")
5049
51-
```shell
52-
flask run
53-
```
50+
```shell
51+
flask run
52+
```
5453
5554
### Deployment
5655
@@ -64,21 +63,21 @@ Steps for deployment:
6463
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.)
6564
3. Provision and deploy all the resources:
6665
67-
```shell
68-
azd up
69-
```
66+
```shell
67+
azd up
68+
```
7069
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.
7271
7372
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.
7473
75-
![Screenshot of Flask restaurants website](screenshot_website.png)
74+
![Screenshot of Flask restaurants website](screenshot_website.png)
7675
7776
5. When you've made any changes to the app code, you can just run:
7877
79-
```shell
80-
azd deploy
81-
```
78+
```shell
79+
azd deploy
80+
```
8281
8382
### CI/CD pipeline
8483
@@ -101,4 +100,4 @@ azd monitor --overview
101100
102101
## Getting help
103102
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).

models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def validate_rating(self, key, value):
2929
return value
3030

3131
def __str__(self):
32-
return f"{self.restaurant.name} ({self.review.date:%x})"
32+
return f"{self.user_name}: {self.review_date:%x}"

0 commit comments

Comments
 (0)