-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (33 loc) · 1.21 KB
/
app.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
from flask import Flask, render_template, jsonify, request
from database import get_jobs_from_db, get_job_from_db, add_application_to_db
app = Flask(__name__)
#route to this function when nothing succeeds the "/" in the url
@app.route('/')
def hello_careers():
#Get the Jobs from the MySQL database hosted in the cloud
jobs = get_jobs_from_db()
#Render the home.html page
return render_template('home.html', jobs = jobs)
#route to this function when "/api/jobs" is in the url
@app.route('/api/jobs')
def list_jobs():
#Get the Jobs from the MySQL database hosted in the cloud
jobs = get_jobs_from_db()
#return a JSON with the jobs list
return jsonify(jobs)
@app.route('/job/<id>')
def show_job(id):
job = get_job_from_db(id)
if not job:
return "Not Found", 404
return render_template('jobpage.html', job = job)
#Use POST method to get form data and populate SQL Database
@app.route('/job/<id>/apply', methods= ['post'])
def apply_job(id):
data = request.form
print(data)
job = get_job_from_db(id)
add_application_to_db(id, data)
return render_template('submission.html', application = data, job = job)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=81, debug = True)