提问人:zahra shokrizadeh 提问时间:8/14/2023 最后编辑:zahra shokrizadeh 更新时间:8/15/2023 访问量:50
错误“列表匹配查询不存在”的原因。
The cause of the error "List matching query does not exist."
问:
我正在编写一个 Django 拍卖程序,在程序的最后几关,当我编写代码来选择拍卖的获胜者并使用 sqlite 创建相应的表时,我遇到了这个错误。此错误后,主页上将不显示任何产品,也无法看到产品信息。 此错误的原因是什么?
我更改了表的列的名称,但它没有效果,其余代码在创建此表之前正在工作。
Traceback (most recent call last):
File "C:\Users\N\AppData\Roaming\Python\Python311\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\N\AppData\Roaming\Python\Python311\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\N\Desktop\New folder\commerce\auctions\views.py", line 72, in item_detail
bid_desc = List.objects.get(pk = bidid, active_bool = True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\N\AppData\Roaming\Python\Python311\site-packages\django\db\models\manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\N\AppData\Roaming\Python\Python311\site-packages\django\db\models\query.py", line 637, in get
raise self.model.DoesNotExist(
^
Exception Type: DoesNotExist at /auctions/1
Exception Value: List matching query does not exist.
这些代码与显示和模板中的获胜部分相关。
# item detail page
def item_detail(request, bidid):
bid_desc = List.objects.get(pk = bidid, active_bool = True)
nowbids = Bidmodel.objects.filter(listb_id = bidid)
return render(request, "auctions/item_detail.html",{
"list": bid_desc,
"comments" : Comments.objects.filter(listc_id = bidid),
"now_bid": minbid(bid_desc.first_bid, nowbids),
})
# winner
def winner(request):
bid_id = request.GET["listid"]
nowbids = Bidmodel.objects.filter(listb_id = bid_id)
biddesc = List.objects.get(pk = bid_id, active_bool = True)
maxbid = minbid(biddesc.first_bid, nowbids)
try:
winner_who = Bidmodel.objects.get(bid = maxbid, listb_id = bid_id)
winner_list = List.objects.get(id = bid_id)
win = Winner(win_list = winner_list, user = winner_who.user)
winners_name = winner_who.user
except:
winner_list = List.objects.get(first_bid = maxbid, id = bid_id)
win = Winner(win_list = winner_list, user = winner_list.user)
winners_name = winner_list.user
biddesc.active_bool = False
biddesc.save()
win.save()
messages.success(request, f"{winners_name} won {win.win_list.title}.")
return redirect("index")
# check winner
def winner_check(request):
try:
yourwin = Winner.objects.filter(user = request.user.username)
except:
yourwin = None
return render(request, "auctions/winner_check.html",{
"user_winlist" : yourwin,
})
{% extends "auctions/layout.html" %}
{% block body %}
<h2>Your Winnings</h2>
<div>
{% for list in user_winlist %}
<div>
<a>{{list.bid_win_list.title}}</a>
<a>{{list.bid_win_list.category}}</a>
<img src="{{ list.bid_win_list.image_url }}">
<p>{{ list.bid_win_list.descRIPTION }}</p>
<div>This bid was listed by <a>{{ list.bid_win_list.user }}</a>.</div>
</div>
{% endfor %}
</div>
CREATE TABLE auctions_winner(
id INTEGER PRIMARY KEY AUTOINCREMENT,
user TEXT,
win_list_id INTEGER NOT NULL
);
答: 暂无答案
评论
/auctions/1
item_detail
active_bool = True
bidid