2

我是 python 的初学者,正在尝试下面的教程:http: //net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/

我创建了一个具有以下正文的模板:

<div class="container">
    <h1>First Blog</h1>
    <hr />
    {% for post in posts %}
        <div class="post">
        <h2>{{ post.title }}</h2>
        <h3>Posted on {{ post.timestamp }} by {{ post.author }}</h3>
        <p>{{ post.bodytext }}</p>
        </div>
        <hr />
    {% endfor %}
</div>

views.py 文档有以下代码:

from django.shortcuts import render_to_response
from blog.models import posts
def home(request):
    entries = posts.objects.all()[:10]
    return render_to_response('index.html', {'posts' : entries})

该网站显示以下内容:

First Blog

{% for post in posts %}
{{ post.title }}

Posted on {{ post.timestamp }} by {{ post.author }}

{{ post.bodytext }}

{% endfor %}

如何让网站显示我数据库中的数据?

4

0 回答 0