Skip to content

Commit d3d14f7

Browse files
committed
Adding stackoverflow code
1 parent 6145fa6 commit d3d14f7

File tree

7 files changed

+630
-37
lines changed

7 files changed

+630
-37
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
env/
2-
.vscode/
2+
.vscode/
3+
4+
*.csv

README.md

+5-34
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,21 @@
11

22
## Prerequisites
3-
To complete this tutorial:
3+
To use this demo app:
44

55
- [Install Python 3](https://www.python.org/downloads/)
66
- [Install Docker Community Edition](https://www.docker.com/community-edition)
77
- (Optional) [Install the Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)
88

9-
## Create app and run it locally
9+
## Run locally
1010

11-
First let's write our app paste the following code into ```main/app.py```:
12-
13-
```python
14-
from flask import Flask
15-
app = Flask(__name__)
16-
17-
@app.route('/')
18-
def hello_world():
19-
return 'Hello, World!'
20-
21-
if __name__ == '__main__':
22-
app.run()
23-
```
24-
25-
Now let's create a dockerfile for the app, we'll use an Alpine Linux container with an NGINX web server. Put the following in a file named `Dockerfile`:
26-
27-
```Dockerfile
28-
FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7
29-
30-
ENV LISTEN_PORT=8000
31-
EXPOSE 8000
32-
33-
COPY /app /app
34-
```
35-
36-
Now build and run the docker container:
11+
To build and run the docker container locally:
3712
```
38-
docker build --rm -t flask-quickstart .
39-
docker run --rm -it -p 8000:8000 flask-quickstart
13+
docker build --rm -t stackoverflow-flask .
14+
docker run --rm -it -p 8000:8000 stackoverflow-flask
4015
```
4116

4217
Open a web browser, and navigate to the sample app at ```http://localhost:8000.```
4318

44-
You can see the Hello World message from the sample app displayed in the page.
45-
46-
![Flask app running locally](https://docs.microsoft.com/en-us/azure/app-service/media/app-service-web-get-started-python/localhost-hello-world-in-browser.png)
47-
4819
In your terminal window, press Ctrl+C to exit the web server and stop the container.
4920

5021
If you make code changes you can re-run the docker build and run commands above to update the container.

app/main.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
app = Flask(__name__)
33

44
@app.route('/')
5-
def hello_world():
6-
return 'Hello, World!'
5+
def index():
6+
return app.send_static_file('index.html')
7+
8+
@app.route('/api/data')
9+
def get_data():
10+
return app.send_static_file('data.json')
711

812
if __name__ == '__main__':
913
app.run()

0 commit comments

Comments
 (0)