-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
112 lines (76 loc) · 3.35 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from flask import Flask, render_template, request, redirect, url_for
import requests, json
app = Flask(__name__)
@app.route("/")
def index():
response = requests.get('http://127.0.0.1:5000/api/course').text
courses = json.loads(response)
response = requests.get('http://127.0.0.1:5000/api/student').text
students = json.loads(response)
if students['status'] == 404:
students["message"] = []
if courses['status'] == 404:
courses["message"] = []
return render_template('index.html', courses=courses["message"], students=students["message"] )
@app.route("/add_student", methods=['POST'])
def add_student():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
course = request.form['comp_select']
data = {'name': name, 'email': email, 'course': course}
response = requests.post('http://127.0.0.1:5000/api/student', data=json.dumps(data)).text
print(response)
return redirect(url_for('index'))
@app.route("/del_student/<int:id>", methods=['GET'])
def del_student(id):
if request.method == 'GET':
response = requests.get(f'http://127.0.0.1:5000/api/student/delete/{id}').text
print(response)
return redirect(url_for('index'))
@app.route('/edit_student/<id>', methods=['POST', 'GET'])
def edit_student(id):
response = requests.get(f'http://127.0.0.1:5000/api/student/{id}').text
student = json.loads(response)
response = requests.get('http://127.0.0.1:5000/api/course').text
courses = json.loads(response)
return render_template('edit-student.html', student=student['message'], courses=courses["message"])
@app.route('/update_student/<id>', methods=['POST'])
def update_student(id):
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
course = request.form['comp_select']
data = {'name': name, 'email': email, 'course': course}
response = requests.post(f'http://127.0.0.1:5000/api/student/{id}', data=json.dumps(data)).text
print(response)
return redirect(url_for('index'))
@app.route("/add_course", methods=['POST'])
def add_course():
if request.method == 'POST':
name = request.form['name']
data = {'name': name}
response = requests.post('http://127.0.0.1:5000/api/course', data=json.dumps(data)).text
print(response)
return redirect(url_for('index'))
@app.route("/del_course/<int:id>", methods=['GET'])
def del_course(id):
if request.method == 'GET':
response = requests.get(f'http://127.0.0.1:5000/api/course/delete/{id}').text
print(response)
return redirect(url_for('index'))
@app.route('/edit_course/<id>', methods=['POST', 'GET'])
def edit_course(id):
response = requests.get(f'http://127.0.0.1:5000/api/course/{id}').text
course = json.loads(response)
return render_template('edit-course.html', course=course['message'])
@app.route('/update_course/<id>', methods=['POST'])
def update_course(id):
if request.method == 'POST':
name = request.form['name']
data = {'name': name}
response = requests.post(f'http://127.0.0.1:5000/api/course/{id}', data=json.dumps(data)).text
print(response)
return redirect(url_for('index'))
if __name__ == "__main__":
app.run(port=5001, debug=True)