I want to delete an object via clicking on a glyphicon wrapped in a form. To do this, my function looks like this:
def deleteHabit(request, id):
print('deleteHabit')
habit_to_delete = get_object_or_404(Habit, id=id)
print(habit_to_delete)
if (request.method == 'POST'):
form = HabitForm(instance=habit_to_delete)
if form.is_valid(): # checks CSRF
print('delete') # normally habit_to_delete.delete()
return redirect('renderOverview') # wherever to go after deleting
else:
# Not Working
return render(request, 'overview/habit_delete_confirm', args)
My understanding of Post and Get is the 'Post' condition does roughly the deleting part and the 'Get' condition renders a confirmation page for example to confirm the deletion. However, the object will be deleted, but by clicking the form it redirects to success_url and does not show a confirmation page. What's wrong on the code snippet above?