问答详情
源自:4-6 实现上下篇文章跳转

为什么定义的previous_index和next_index是灰色的??

https://img3.mukewang.com/5d3913f50001439104750462.jpg运行失败啊

提问者:闲吃小栗子 2019-07-25 10:29

个回答

  • 慕九州1502500
    2020-05-08 13:42:04

    previous_article = all_article[previous_index]
    next_article = all_article[next_index]

    这两句上哪去了

  • 慕粉2357434992
    2019-10-16 22:10:38

    def get_detail_page(request, article_id):
        all_article = Article.objects.all()
        curr_article = None
        previous_article = None
        next_article = None
        for index, article in enumerate(all_article):
            if index == 0:
                previous_index = 0
                next_index = index + 1
            elif index == len(all_article) - 1:
                previous_index = index - 1
                next_index = index
            else:
                previous_index = index - 1
                next_index = index + 1
            previous_article = all_article[previous_index]
            next_article = all_article[next_index]
            if article.article_id == article_id:
                curr_article = article
                break
        section_list = curr_article.content.split('\n')
        return render(request, 'blog/detail.html', {
            'curr_article': curr_article,
            'section_list': section_list,
            'previous_article': previous_article,
            'next_article': next_article
        })

    我是这样的