ページ postlogin.html の models.py にあるものを表示しようとしていますが、データベースにデータがあっても、ページには何も表示されません。views.py の part(posts = NewRecipePost.objects.all().order_by("-post_date")) でデータを呼び出すのに問題があると思います。以下のコードはコードの一部にすぎず、すべてが正しくインポートされ、正しくインデントされています。
アドバイスをいただければ幸いです。ありがとう
models.py
from django.db import models
class NewRecipePost(models.Model):
title = models.CharField('title', blank=False, max_length=50 )
post_date = models.DateField(auto_now_add=True)
ingredients = models.TextField('ingredients', max_length=1000)
content = models.TextField('content', max_length=1000)
def __unicode__(self):
return self.title
フォーム.py
from recipeapp.models import NewRecipePost
class NewRecipeForm(forms.ModelForm):
class Meta:
model = NewRecipePost
ビュー.py
def my_view (リクエスト、ユーザー名):
posts = NewRecipePost.objects.all().order_by("-post_date")
if request.method == 'POST':
form = NewRecipeForm(request.POST)
if form.is_valid():
form.save()
else:
form = NewRecipeForm()
variables = RequestContext(request, {'form':form,'username':username, 'posts':posts})
return render_to_response('postlogin.html',variables)
postlogin.html
<ul>
{% for post in posts.object_list %}
<div>{{post.title}}</div>
<div>{{post.post_date}}</div>
<ul>
<div>{{post.ingredients}}</div>
<div>{{post.content}}</div>
</ul>
{% endfor %}
</ul>