67 <h2>Latest Posts</h2>
68
69 <ul>
70 {% for post in posts %}
71 <li><a href="{{ post.get_absolute_url }}">{{post.title}}</a></li>
72 {% endfor %}
73 </ul>
这是我的基本模板,当我单击帖子时,在第 70 行出现错误:
TypeError at /blog/posts/indiana-was-dogs-name/
'Blog' object is not iterable
我的博客模型:
class Blog(models.Model):
title = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
body = models.TextField()
posted = models.DateField(db_index=True, auto_now_add=True)
category = models.ManyToManyField(Category)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/blog/posts/%s/" % self.slug
我的索引视图:
def 索引(请求):
variables = RequestContext(request, {
'categories': Category.objects.all(),
'posts': Blog.objects.filter(posted__lte=datetime.now()).order_by('-posted', 'title')
})
return render_to_response('index.html',variables)
有一些关于这样的错误的帖子,但不包括我的问题