[Answered ]-Django template comparing strings returning false?

1👍

Change your logic;

First:

listing = Listing.objects.all().filter(title=title).first()

# Change variable name, you should name your variables with their purpose
author = listing.user

return render(request, "auctions/listing.html", {
     "author": author
})

Second:

# No need to use {{ }} in condition because `Jinja` does it for you.
{% if request.user == author %} # {% if request.user.username == author.username %}
    <form action="listing" method="GET">
        <input class="btn btn-primary" type="submit" value="Close Listing" name="close">
    </form>
{% endif %}

👤Zkh

Leave a comment