gpt4 book ai didi

error-handling - pk = request我有一些错误。由于出现此错误,我似乎无法将我的储备金链接到另一页

转载 作者:行者123 更新时间:2023-12-03 08:48:08 24 4
gpt4 key购买 nike

def reserve(request):
if request.method=="POST":
user=User.objects.get(pk=request.POST['user'])
**book = Book.objects.get(pk=request.POST['book'])**
book.isAvailable=True
book.save()
reservation=Reserve(dateLoaned=datetime.now(),book=book, user=user)
reservation.save()
reservations=Reserve.objects.all()
return redirect('/library/reservations/')
else:
user=User.objects.all()
book=Book.objects.all()
return render(request, 'reserve.html',{"users":user, "book":book})

我的书有一些错误= Book.objects.get(pk = request.post [book'])
我正在做一个需要在星期一提交的项目。请帮助!

reserve.html
{% extends 'base.html' %}
{% load static %}
{% block title %}
Reserve
{% endblock %}
{% block maincontent %}
<form action="../reserve/" method="post">
{% csrf_token %}
<br>
<div class="table">
<input value="{{ book.title }}" class="form-control"
id="exampleFormControlInput1" enabled>
</div>
<div class="form-group">
<td>
<img src = "{{ book.cover }}" height="150" width="100"/>
</td>
</div>
<div class="form-group">
<br>
<label for="FormControlSelect1">Select Users</label>
<select class="form-control" id="FormControlSelect1" required
name="user">
{% for user in users %}
<option value="{{ user.pk }}">{{ user }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success btn-block">Reserve</button><br>
</div>
<input type="hidden" value="{{ book.pk }}" name="book" />
</form>
{% endblock %}

我的储备HTML可能有一些错误。它应该将我的储备金链接到另一页。但是没有。

最佳答案

上图MultiValueDictKeyError中的错误。您必须替换以下代码

reservation = Reserve.objects.get(pk=request.POST['reservation'])


reservation = Reserve.objects.get(pk=request.POST.get('reservation'))

关于error-handling - pk = request我有一些错误。由于出现此错误,我似乎无法将我的储备金链接到另一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48834673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com