generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
59 lines (45 loc) · 1.46 KB
/
run.py
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
52
53
54
55
56
57
58
59
import os
import json
from flask import Flask, render_template, request, flash
if os.path.exists("env.py"):
import env
# variable 'app'
# first argument of th3e Flask class is 'name'
app = Flask(__name__)
app.secret_key = os.environ.get("SECRET_KEY")
# Decorator : A way of wrapping functions
# (pie-notation)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/about")
def about():
data = []
with open("data/company.json", "r") as json_data:
data = json.load(json_data)
return render_template("about.html", page_title="About", company=data)
@app.route("/about/<member_name>")
def about_member(member_name):
member = {}
with open("data/company.json", "r") as json_data:
data = json.load(json_data)
for obj in data:
if obj["url"] == member_name:
member = obj
return render_template("member.html", member=member)
@app.route("/contact", methods=["GET", "POST"])
def contact():
if request.method == "POST":
flash("Thanks {}, we have received your message!".format(
request.form.get("name")))
return render_template("contact.html", page_title="Contact")
@app.route("/careers")
def careers():
return render_template("careers.html", page_title="Careers")
# '__main__' is default module
if __name__ == "__main__":
app.run(
host=os.environ.get("IP", "0.0.0.0"),
port=int(os.environ.get("PORT", "5000")),
debug=True,
)