Sep-10-2020, 01:40 AM
Hey guys I'm trying to pass a value through the render method and it only accepts dictionaries. But I only want it to get one dataset. So I'm doing it by searching through data with the the same "title". I have it only grabbing the first dataset using the first() method.
However, now I can't iterate through it since it's only one dataset.
If I try to just user query.title - it shows nothing - I get no error though - it just doesn't show the title on the HTML page.
If I try to iterate though it, it gives me an error that the object is not iterable.
How can I display the one dataset result that I got from my query in HTML?
Here is my code:
views.py:
However, now I can't iterate through it since it's only one dataset.
If I try to just user query.title - it shows nothing - I get no error though - it just doesn't show the title on the HTML page.
If I try to iterate though it, it gives me an error that the object is not iterable.
How can I display the one dataset result that I got from my query in HTML?
Here is my code:
views.py:
def post(request, title, description, price, category): title = title description = description price = price category = category query = NewPost.objects.filter(title = title).first() return render(request, "auctions/post.html", { "queries": query })post.html :
{% extends "auctions/layout.html" %} {% block body %} {% for query in queries %} <h2>{{ query.title}}</h2> {% endfor %} {% endblock %}