django模型在使用templete时返回空,但结果中没有模板
当我在django模型在使用templete时返回空,但结果中没有模板,django,django-models,django-templates,Django,Django Models,Django Templates,当我在view.py中有这个时 def index(request): products = product_page.objects.order_by('name')[:5] output = ', '.join([q.name for q in products]) return HttpResponse(output) 它返回test1,test2 但是什么时候改成 def index(request): products = product_page.o
view.py中有这个时
def index(request):
products = product_page.objects.order_by('name')[:5]
output = ', '.join([q.name for q in products])
return HttpResponse(output)
它返回test1,test2
但是什么时候改成
def index(request):
products = product_page.objects.order_by('name')[:5]
context = {
'products': products,
}
return render(request, 'dashboard/index.html', context)
并且在/dashboard/template/dashboard中有一个index.html
<html>
<head>
<title>test</title>
</head>
<body>
<h1>PRODUCTS LISsssT</h1>
{% if products %}
test in if
{{produtcs}}
<ul>
{% for product in produtcs %}
test in for
<li><a href="#">{{ product.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No product are available.</p>
{% endif %}
<ul><li>hello</li></ul>
</body>
</html>
测试
产品LISsssT
{%if产品%}
在if中测试
{{produtcs}}
{produtcs%中产品的%s}
报考
{%endfor%}
{%else%}
没有可用的产品
{%endif%}
- 你好
我没有
标签,我使用django==2.2.8您似乎有一个输入错误,{produtcs%中的产品百分比}应该是{products%中的产品百分比}什么?我不明白“produtcs”应该是“products”哦,我犯了多大的错误啊!谢谢你。谢谢