我不明白,因為這段代碼之前作業正常,現在我在提交表單時收到上述錯誤。視圖.py 檔案
class BookingView(FormView):
form_class = AvailabilityForm
template_name = "availability.html"
def form_valid(self, form):
data = form.cleaned_data
bookingList = Appointment.objects.filter()
for booking in bookingList:
if booking.start == data["start_time"]:
print("Cant be booked")
return HttpResponse("Cant be booked")
else:
booking=Appointment.objects.create(
name=data["name"],
start=data["start_time"],
end=data["end_time"]
)
booking.save()
return HttpResponse("can be booked")
uj5u.com熱心網友回復:
您的查詢集為空,因此您的代碼永遠不會達到 for 回圈內的條件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381156.html
