views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:quora-django 作者: hndrxr 项目源码 文件源码
def index(request, page):
    if not request.user.is_authenticated:
        return redirect('account:signup')
    profile = Profile.objects.get(user=request.user)
    following = Follow.objects.filter(profile=profile).all()
    followed_topics = []
    for topic in following:
        followed_topics.append(topic.topic)
    queries = [Q(topic=topic) for topic in followed_topics]
    if queries:
        query = queries.pop()
        for item in queries:
            query |= item
        questions = Question.objects.filter(query).order_by('-created_at').all()
    else:
        questions = []
    paginator = Paginator(questions, 10)
    questions = paginator.page(page)
    print(questions)
    return render(request, "question/index.html", {
        "questions": questions, "following": followed_topics
    })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号