NOReverseMatch в /bid/2
Я получаю ошибку NoReverseMatch at /bid/2, можете ли вы сказать, что я делаю неправильно и какое может быть решение. Я новичок в Django Спасибо. Игнорировать:- sadfgnasgdsfhfgjhn fgdshsdgh fd dgsdfg dsf ds asgdfhrtyn sdfgh ehe ereg sdfgsfghhsdje sdfghshsdherh Это мой шаблон URL :-
urlpatterns = [
path("", views.index, name="index"),
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("create/", views.create_listing,name="create_listing"),
path("submit/<str:username>",views.submit,name="submit"),
path("<int:list_id>",views.item,name="item"),
path("comments/<int:list_id>",views.comment,name="comment"),
path("category/<int:item_category>",views.category,name="category"),
path("bid/<int:list_id>",views.set_bid,name="set_bid"),
]
Это моя функция просмотра:-
def set_bid(request,list_id):
price = request.POST['bid']
username = request.user.username
item = Listing.objects.get(pk=list_id)
b=Bids.objects.filter(item=item)
if b:
b.update(bid=price)
b.save()
else:
b = Bids(bid=price,user=username,item=item)
b.save()
item.current_bidder = username
item.save()
return render(request,"auctions/item.html",{
"listings":Listing.objects.get(pk=list_id),
"comments":Comments.objects.all().filter(comment_id=list_id),
"bid":Bids.objects.all().filter(item=item),
})
Это шаблон элемента, из которого вызывается шаблон url:-
{% extends "auctions/layout.html" %}
{% block body %}
{% if message %}
<div class="alert alert-danger ">{{ message }}</div>
{% endif %}
<div class="item-block">
<h3>Listing: {{ item.name }} <button class="btn btn-primary" type="button">Add to Watch list</button></h3>
<img src="{{ item.image }}" alt="No Image">
<p>{{ item.description }}</p>
{% if bid %}
<h4>${{ bid.bid }} by {{ item.current_bidder }}</h4>
{% else %}
<h4>${{ item.price }}</h4>
{% endif %}
<form class="" action="{% url 'set_bid' item.id %}" method="post">
{% csrf_token %}
<input type="number" name="bid" placeholder="Bid"><br>
<input id="bid" type="submit" value="Place Bid">
</form>
</div>
<h5>Details:-</h5>
<ul>
<li>Listed by: {{ item.user }}</li>
<li>Category: {{ item.category }}</li>
</ul>
<hr>
<h1>Comments</h1>
<!-- TODO: -->
{% for comment in comments %}
<div class="comment">
<h6>{{ comment.user }}</h6>
<p>{{ comment.comment }}
<button class="float-right"><a href=""><img src="https://img.icons8.com/office/16/000000/delete-sign.png"/></a></button>
</p>
</div>
{% endfor %}
<form action="{% url 'comment' item.id %}" method="post">
{% csrf_token %}
<label for="Your comment">Your comment</label><br>
<textarea name="comment" rows="5" cols="80"></textarea>
<input type="submit" value="Post">
</form>
{% endblock %}
Вы не отправили элемент в контексте при рендеринге html. Добавьте элемент в контекст и все будет работать.
return render(request,"auctions/item.html",{
...
'item': item
})