/
run.py
52 lines (43 loc) · 1.72 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
# This is the entry file for the application
import os
import json
from flask import Flask, render_template, request, flash
app = Flask(__name__) # Create instance of the Flask class. It is a place holder for the current module
app.secret_key = 'some_secret' # This is needed for flash to work
#decorator :
@app.route('/')
def index():
# return "<h1>Hello World</h1><h2>This is a Flask Application</h2>"
return render_template("index.html", page_title="Home Page")
@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 = 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 "<h1>" + member["name"] + "</h1>"
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["name"]))
print("Hello, POST method used.")
print(request.form)
print("Name: " + request.form["name"])
return render_template("contact.html", page_title="Contact")
@app.route('/careers')
def careers():
return render_template("careers.html", page_title="Vacancies", subtitle="Come work with us!")
if __name__ == '__main__':
app.run(host=os.environ.get('IP'), # run the server
port=int(os.environ.get('PORT')),
debug=True)