[英]I am trying to import my database values, but the results are not being displayed, even though the table structure is correct
在 views.py 中創建表
def products(request):
if request.method=='POST':
form = ProductForm(request.POST)
if form.is_valid():
try:
form.save()
return redirect('show')
except:
pass
else:
form = ProductForm()
return render(request,'show.html',{'form':form})
這是來自 show.html 文件的內容。
<tbody>
{% for items in products %}
<tr>
<td>{{ items.pid }}</td>
<td>{{ items.pname }}</td>
<td>{{ items.pprice }}</td>
<td>
<a href="/edit/{{ items.id }}"><span class="glyphicon glyphicon-pencil" >Edit</span></a>
<a href="/delete/{{ items.id }}"> <span class="glyphicon glyphicon-remove">Delete</span></a>
</td>
</tr>
{% endfor %}
</tbody>
數據庫值未顯示在網頁上。
您傳遞給show.html
模板的唯一上下文是form
。
在您的模板中使用products
,並且由於此變量不存在,您沒有得到任何 output。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.