Answer the question
In order to leave comments, you need to log in
Is it normal practice to delete, change, create data with a get request, not a post?
I have such a view where I delete a comment by clicking on a link in the form of a button, I delete it with a get request, is it okay to use a get request for this, instead of post?
class DeleteCommentView(View):
def get(self, request, **kwargs):
comment_id = kwargs.get('pk')
user = request.user
comment = Comment.objects.get(id=comment_id)
comment.delete()
return redirect('profiles:profile-detail', slug=user.profile.slug)
<a href="{% url 'posts:comment-delete' pk=comment.pk %}"><i class="bi bi-x-circle delete-com"></i></a>
Answer the question
In order to leave comments, you need to log in
Abnormal. HTTP clients, including the browser, rely on the idempotency of GET requests, and therefore can perform it without asking or repeat an arbitrary number of times. So don't be surprised if after visiting the page with comments, they are deleted, although you did not click anything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question