[英]Render a dictionary with object list as values in django but template not showing values
我试图在我从视图文件呈现的模板中显示字典值。 但它没有显示任何价值。 在我的 html 模板中显示我只是空白或没有任何错误。
视图.py
class BuyView(TemplateView):
template_name = 'shop/buy.html'
red_templateName = 'shop/receipt.html'
def get(self, request, product_id):
product = get_object_or_404(Product, pk=product_id)
args = {'product':product}
return render(request, self.template_name, args)
def post(self, request, product_id):
product = Product.objects.get(id=product_id)
if request.POST['address'] and request.POST['quantity']:
order = Order()
order.or_proName = product.pro_name
order.or_companyName = product.companyName
order.or_quatity = request.POST['quantity']
order.or_quatity = int( order.or_quatity)
orderPrice = order.or_quatity*product.Sale_Price
order.or_bill = 100 + orderPrice
order.pub_date = timezone.datetime.now()
product.Quantity -= order.or_quatity
product.save()
order = order.save()
args = {'order':order}
return render(request, self.red_templateName, args)
else:
return render(request, self.template_name, {'error':'Please Fill the address field'})
模板.html
{% extends 'base.html' %}
{% block content %}
<div>
<div class="container p-5" style="border:1px solid gray;">
<small class="lead" >Your Order Receipt: </small>
{{ order.or_id }}
{{order.or_proName}}
{{order.or_companyName}}
{{order.or_quatity}}
{{order.pub_date}}
Deliever Chargers=100
-----------------------
Total = {{or_bill}}
</div>
</div>
{% endblock %}
您的模板文件名应与以下内容匹配
red_templateName = 'shop/receipt.html'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.