-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_19.py
More file actions
51 lines (43 loc) · 1.16 KB
/
sample_19.py
File metadata and controls
51 lines (43 loc) · 1.16 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, url_for
# create a Flask app for sample_19
app = Flask(__name__)
# define view function for "/" url
@app.route("/")
def Hello():
return "Hello World!"
# define view function for "/info"
@app.route("/info")
def info():
name = "Abi"
html = """
<b><center>
Hello, World!
My name is {}
</center></b>
""".format(name)
return html
@app.route("/name/<yourname>")
def display_name(yourname: str):
return "Hello, World! {}".format(yourname)
@app.route("/age/<int:age>")
def display_age(age: int):
return "You are {} years old".format(age)
@app.route("/say_hello")
def say_hello():
html = """
<a href={}> Hello, World!</a>
"""
# url_for gives href the link to hello_from_cat
# in other words,
# href={} becomes href="/hello_from_cat"
html = html.format(url_for("hello_from_cat"))
return html
@app.route("/hello_from_cat")
def hello_from_cat():
# links src to static/cat.jpg
return "<img src={}>".format(
url_for("static", filename="cat.jpg")
)
if __name__ == "__main__":
# run the Flask app in localhost at port 5000
app.run(host="0.0.0.0", port=5000, debug=True)