当我单击输入图像时,我试图在django中更改布尔值,我想我已经做到了,但是现在当我尝试在html中比较此布尔值时,它并没有带来正确的值,而是始终将其作为False(sn6 .jpg)
View.py
def reservacion(request):
if request.method == "POST":
estatus = Asientos.objects.get(asiento=1)
if estatus.status == True:
estatus.status = False
estatus.save()
else:
estatus.status = True
estatus.save()
return render(request,"reservacion.html")
Models.py
class Reserva(models.Model):
mesa = models.CharField(max_length=2,primary_key=True)
asiento = models.ForeignKey(Asientos)
def __str__(self):
return self.mesa
html--在这里,我的if语句更改了数据库上布尔值的值,但始终以False(sn6.jpg)显示图像
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<div class="row">
{% if estatus.status == True%}
<div class="col"><input class="d-block w-100" type="image" src="{%static "/img/s6.jpg" %}" name="1" value=""></div>
{% else %}
<div class="col"><input class="d-block w-100" type="image" src="{%static "/img/sn6.jpg" %}" name="1" value=""></div>
{% endif %}
</form>
我丢失了什么吗?单击并提交值时如何获得其他oimage?
答案 0 :(得分:1)
两点:
render(request,"reservacion.html", {‘estatus’: estatus})
True
进行比较,就足够了:if estatus.status