Add the ability to add/delete users from overview page

This commit is contained in:
Peter Stockings
2023-03-10 22:27:30 +11:00
parent 3a506b83a5
commit 56cf6813b7
3 changed files with 52 additions and 38 deletions

8
app.py
View File

@@ -83,7 +83,7 @@ def users():
elif request.method == 'POST':
# create a new user
data = request.json
data = request.form
name = data['name']
# create a new user and add it to the database
@@ -91,7 +91,8 @@ def users():
db.session.add(new_user)
db.session.commit()
return jsonify({'message': 'User created successfully.'}), 201
users = User.query.all()
return render_template('users.html', users=users)
@app.route('/user/<int:user_id>', methods=['DELETE'])
@@ -100,7 +101,8 @@ def delete_user(user_id):
if user:
db.session.delete(user)
db.session.commit()
return jsonify({'message': 'User deleted successfully.'}), 200
users = User.query.all()
return render_template('users.html', users=users)
else:
return jsonify({'error': 'User not found.'}), 404