簡體   English   中英

我是否在 django 上的模板上遺漏了什么

[英]Am i missing something on templates on django

這是我在 django 項目的 html 文件上的代碼。 我在這個 function 上使用這個代碼

def home(request):
    context = {
        'post': posts
    }
    return render(request,'blog/home.html',context

當我看到頁面源時它不顯示任何內容它只是 bacis html 代碼頭和身體空

<html>
<head>
<title> </title>
</head>
<body>
    {% for post in posts %}
        <h1>{{post.title}}</h1>
        <p>By {{post.author}} on {{post.date_posted}}</p>
        <p>{{post.content}}</p>
    {% endfor %}
</body>
</html>```

這是一個錯字。 您需要從以下位置更改視圖中的上下文:

context = { 'post': posts } 

 context = { 'posts': posts } 
             ^^^^^^^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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