-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
39 lines (28 loc) · 822 Bytes
/
hello.py
File metadata and controls
39 lines (28 loc) · 822 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
30
31
32
33
34
35
36
37
38
39
from flask import Flask, render_template
#Create a Flask Instance
app = Flask(__name__)
#Create a route decorator
@app.route('/')
#def index():
# return"<h1>Hello World!</h1>"
def index():
first_name = "John"
stuff = "This is bold text"
favorite_pizza = ["Pepperoni", "Cheese", "Mushrooms", 41]
return render_template("index.html",
first_name=first_name,
stuff=stuff,
favorite_pizza = favorite_pizza)
# localhost:5000/user/john
@app.route('/user/<name>')
def user(name):
return render_template("user.html", user_name=name)
#Create Custom Error Pages
#Invalid URL
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html"), 404
#Internal Server Error
@app.errorhandler(500)
def page_not_found(e):
return render_template("500.html"), 500