这个 Python 语法错误在哪里?

Where is this Python syntax error?

我要回到 Python 并且至少有一点我在 0.9.x Pinax 安装中犯了语法错误。我在这里要做的是添加一个额外的过滤层(在默认的可选过滤之上,该过滤提供允许用户查看所有博客条目或一个特定用户的所有博客条目的功能)。

在另一个文件 custom.py 中,我有一个函数 threshold_check() 旨在以另一种方式进行过滤;它有两个参数,一个 Django 用户和几种类型的对象之一,包括博客 post 和 returns,真或假,是否应该包含该项目。

我的代码在我看来是正确的,但 Django 在列表理解的第二行报告语法错误填充 allowed_blogs in:

def blogs(request, username=None, template_name="blog/blogs.html"):
    blogs = Post.objects.filter(status=2).select_related(depth=1).order_by("-publish")
    if username is not None:
        user = get_object_or_404(User, username=username.lower())
        blogs = blogs.filter(author=user)
    allowed_blogs = [blog in blogs.objects.all() if
      custom.threshold_check(request.user, blog)]
    return render_to_response(template_name, {
        "blogs": allowed_blogs,
    }, context_instance=RequestContext(request))

我做错了什么,我需要做什么才能允许引用的 custom.threshold_check() 批准或否决包含在 allowed_blogs 列表中的 Pinax 博客对象?

TIA,

[blog in blogs.objects.all() if
  custom.threshold_check(request.user, blog)]

这无效 Python。也许你的意思是:

[blog for blog in blogs.objects.all() if
  custom.threshold_check(request.user, blog)]