-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (24 loc) · 928 Bytes
/
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
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
employees = [
{"id": 1, "name": "John Doe", "position": "Software Engineer"},
{"id": 2, "name": "Jane Smith", "position": "HR Manager"}
]
@app.route('/')
def home():
return render_template('home.html')
@app.route('/employees')
def employee_list():
return render_template('employee_list.html', employees=employees)
@app.route("/add-employee", methods=['GET', 'POST'])
def add_employee():
if request.method == 'POST':
name = request.form.get('name')
position = request.form.get('position')
new_employee = {"id": len(employees) + 1,
"name": name, "position": position}
employees.append(new_employee)
return redirect(url_for('employee_list'))
return render_template("add_employee.html")
if __name__ == '__main__':
app.run(debug=True)