diff --git a/app.py b/app.py index 34f244e..808b52c 100644 --- a/app.py +++ b/app.py @@ -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/', 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 diff --git a/templates/users.html b/templates/users.html new file mode 100644 index 0000000..db8d768 --- /dev/null +++ b/templates/users.html @@ -0,0 +1,41 @@ + + + + + + + + + {% for u in users %} + + + + + {% endfor %} + +
NameWorkouts
{{ + u.name }} +
+
{{ u.workouts_count }}
+
+
+ + + + +
+
+ + + + +
+
+
+
\ No newline at end of file diff --git a/templates/users_and_workouts.html b/templates/users_and_workouts.html index 12be797..a4dd444 100644 --- a/templates/users_and_workouts.html +++ b/templates/users_and_workouts.html @@ -17,7 +17,7 @@ Cardio Tracker
-
+ @@ -35,44 +35,15 @@

Users

-
- - - - - - - - - {% for u in users %} - - - - - {% endfor %} - -
NameWorkouts
{{ u.name }} -
-
{{ u.workouts_count }}
-
- - - - -
-
-
+
+ + {% with users=users %} + {% include 'users.html' %} + {% endwith %}
- - -