【发布时间】:2016-11-01 14:43:54
【问题描述】:
当我传递上下文时,另一端似乎无法使用它,为了使其更简单并举个例子,我将尝试传递我所有的产品并简单地列出所有产品 id 的列表,它不起作用,当我访问该页面时,我得到的只是一个空白页面。
views.py
def cart(request):
items = [1,2,3,4]
template = loader.get_template("Cafe/cart.html")
ip = get_client_ip(request)
order = current_order.objects.order_by('id')
products = product.objects.order_by('id')
context = {
'order': order,
'products': products,
'items': items
}
return HttpResponse(template.render(request))
cart.html
<head>
{% load static %}
{% load app_filters %}
<link rel="stylesheet" type="text/css" href="{% static 'Cafe/stylesheet.css' %}" />
</head>
<body>
{% for product in products %}
<a>{{product.id}}</a>
{% endfor %}
</body>
models.py
class product(models.Model):
categories = (
('HD', 'Hot Drink'),
('CD', 'Cold Drink'),
('Br', 'Breakfast'),
('Sa', 'Sandwich'),
('Ex', 'Extras'),
('Sp', 'Specials'),
)
product_name = models.CharField(max_length=100)
category = models.CharField(max_length=2, choices=categories, default=categories[0][0])
price = models.FloatField()
我没有看到为什么这不应该起作用的原因,因为相同的概念适用于我制作的所有其他页面。
【问题讨论】: