一切都运行良好,所以无论如何我都假定,但是当我运行服务器并点击我的博客标题时,我得到一个AttributeError说' unicode对象没有属性标签'
继承处理标签的代码
def post_detail(request, year, month, day, post):
post_tags_ids = post.tags.values_list('id', flat=True)
similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
similar_posts = similar_posts.annotate(same_tags=Count('tags')).order_by('-same_tags','-publish')[:4]
post = get_object_or_404(Post, slug=post,status='published',publish__year=year,publish__month=month,publish__day=day)
return render(request,'blog/post/detail.html',{'post': post,'comments': comments,'comment_form': comment_form,'similar_posts': similar_posts})
答案 0 :(得分:0)
您传递的'post'参数似乎不是您所假设的模型实例。我想你需要先获取post对象。假设你传递pk作为帖子:
post_object = get_object_or_404(Post, pk=post)
post_tags_ids = post_object.tags.values_list('id', flat=True)