What is the best practice to delete object in Django? Using simple "a tag" with the link to the view like this:
def deleteStudent(request,id):
student = get_object_or_404(Student, id = id)
student.delete()
return redirect('/')
or using post method:
<form method="POST">
{% csrf_token %}
Are you want to delete this item ?
<input type="submit" value="Yes" />
<a href="/">Cancel </a>
</form>
and in views:
def deleteStudent(request, id):
student = get_object_or_404(Student, id = id)
if request.method =="POST":
student.delete()
return redirect('/')
return render(request, "delete_view.html")
I saw in courses that people use both of the methods (it's example code, I'didn't test it or secure views). So if we can delete objects with "POST" method, can I say in the job interview that "POST method can be also used to delete objects"? Thanks for all answers.