-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflask_web_test.py
More file actions
29 lines (24 loc) · 818 Bytes
/
flask_web_test.py
File metadata and controls
29 lines (24 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from random import randint
from flask import Flask
app = Flask(__name__)
# accessed via <HOST>:<PORT>/get_random
@app.route("/get_random")
def random():
random_number = randint(1, 10)
return {'random': random_number}, 200 # status code
# using default
@app.route('/hello')
@app.route('/hello/<user_name>')
def hello_user(user_name = 'no one'):
return 'Hello ' + user_name, 200 # status code
@app.route("/my")
def my():
return "<a href='www.google.com'> Click Me</a>", 200
# accessed via <HOST>:<PORT>/welcome
@app.route("/welcome")
def welcome():
return "<H1 id='welcome'>Welcome!</H1>", 200 # status code
# host is pointing at local machine address
# debug is used for more detailed logs + hot swaping
# the desired port - feel free to change
app.run(host='127.0.0.1', debug=True, port=5000)