簡體   English   中英

我正在嘗試導入我的數據庫值,但沒有顯示結果,即使表結構是正確的

[英]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 }}">&nbsp;&nbsp;<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM