私は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})
Web サイトには次のように表示されます。
First Blog
{% for post in posts %}
{{ post.title }}
Posted on {{ post.timestamp }} by {{ post.author }}
{{ post.bodytext }}
{% endfor %}
Web サイトにデータベースのデータを表示させるにはどうすればよいですか?