我试图将数据从django视图传递到我的模板,但是由于某种原因,当我试图在模板中呈现数据时,什么都没有发生。但是我可以看到我从模型中得到了正确的数据。我会做错什么
views.py
class PatientBill(CreateView):
model = PatientBill
form_class = PatientBillform
def get(self,request):
form=PatientBillform();
billingservice = Billing.objects.values()
print ('Billingservice',billingservice)
return render(request,'cashier/patientbill.html',{'form':form,'Billingservice':billingservice})
patientbill.html
<form method="post">
{% csrf_token %}
{{ form.patientid }}
<br>
{{ form.totalbill }}
<br>
<label style="font-weight: bold;">Choose a service </label> <select id ="service" style="width: 50%;height: 30px;margin-left: 75px" >
<option disabled selected> -- select an option -- </option>
{% for bservice in Billingservice %}
<option name = "servicedata" value={{bservice.service}}</option>
{% endfor %}
</select>
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored subtn">Calculate</button>
</form>
Billingservice - Billingservice <QuerySet [{'id': 2, 'created': datetime.datetime(2018, 5, 3, 13, 28, 58, 170762, tzinfo=<UTC>), 'price': '2000', 'service': 'Consultation'}]>
您可以通过
get_context_data()
more info here发送变量相关问题 更多 >
编程相关推荐