'I cant delete my quotes in Django? Python

Ive created a Django project where people can enter quotes by different authors. I cant figure out why Im not able to delete quotes on the same page. The user should be able to delete there own quotes

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Main</title>
</head>
<body>
    <header>
        <h1>Welcome, {{request.session.greeting}}</h1>
        <a href='/Edit_Account'>Edit My Account</a>
        <a href='/logout'>Logout</a>
    </header>

    {% for quote in quotes %}
        <p>Posted on: {{review.created_at}}</p>
        {% if quote.user.id == request.session.user_id %}
        <a href='reviews/{{quote.id}}/delete'>Delete this quote</a>
        {% endif %}
        <li>{{quote.author}} {{quote.quote}}</li>
        <a href="/like/{{quote.id}}">Like Quote</a>
        <p>{{ quote.user_likes.count }}</p>
        <p>(Posted by </a><a href='/users/{{quote.user.id}}'>{{quote.creator.first_name}}) </a></p>
        {% endfor %}
    {% for message in messages %}
        <li>{{message}}</li>
    {% endfor %}
    <h2>Add A Quote!</h2>
    <form action="quote/create" method="POST">
        {% csrf_token %}
        <label for="author">Author</label>
        <input type="text" name="author">
        <label for="quote">Quote</label>
        <input type="text" name="quote">
        <button type="submit">Submit</button>
    </form>

</body>
</html>


def delete_quote(request, review_id):
    quote = Quote.objects.get(id = quote_id)
    if quote.user.id == request.session['user_id']:
        quote.delete()
    else:
        messages.error(request, "This isn't yours to delete.")
    return redirect(f'/main')


Solution 1:[1]

First create a html page asking them really they want to delete or not

{% extends 'main.html'%}

{% block content %}

<form method = "POST" action = "">
    {% csrf_token %}
    <p> Are you sure you want to delete "{{obj}}"?</p>
    <a href = "{{request.META.HTTP_REFERER}}" >Go Back</a>
    <input type = 'submit' value='Confirm'/>

</form>


{% endblock content %}

then create a delete view like this


def deleteQuote(request,pk):
    quote = Quote.objects.get(id=pk)
    if request.user != quote.user:
        return HttpResponse("You can't delete quote")
    else:
        if request.method == 'POST':
            quote.delete()
    return render(request,'pages/delete.html',{'obj':quote})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1