django渲染请求dict名称

时间:2013-09-24 13:52:47

标签: python django

views.py

from django.shortcuts import render_to_response
from models import Post
def getRecentPosts(request):
    posts = Post.objects.all()

    # sort by chronological order
    sorted_posts = posts.order_by('-pub_date')

    # display all posts
    return render_to_response('posts.html', {'posts': sorted_posts})

posts.html

<html>
<head>
    <title>My Django Blog</title>
</head>
<body>
{% for post in posts %}
    <h1>{{post.title}}</h1>
    <h3>{{post.pub_date}}</h3>
    {{ post.text }}
{% endfor %}
</body>

此代码工作正常&amp;打印正确的数据....但是,如果我改变

return render_to_response('posts.html', {'posts': sorted_posts})

return render_to_response('posts.html', {'po': sorted_posts})     

{% for post in posts %} to {% for post in po %}
posts.html中的

它无法生成任何数据.....那么视图中的字典名称和模板

之间的关系是什么

0 个答案:

没有答案