I'm trying to get the course.id which the user has clicked, but I don't know how to do so.
Here are the codes:
.py
elif request.method == "POST": # Adds course to favorite courses_dict = db.execute("SELECT * FROM courses;") for course in courses_dict: if request.form.get('name') == course['id']: db.execute("INSERT INTO favorite_courses(user_id, course_id) VALUES (?, ?);", session['user_id'], course['id']) return redirect("/")
.html ` {% for course in courses %}
<hr class="border border-primary">
<form action="/search" method="post">
<button type="submit" name ='{{course.id}}'> Favorite
</button>
</form>
<h2>{{ course.name }}</h2>
{% endfor %} {% endblock %} `
I'm trying to recive the 'course.id' which the user cliks.