ouchaochao
2019-07-10 22:52
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Blog</title> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </head> <body> <div class="container page-header"> <h1>{{ curr_article.title }}</h1> </div> <div class="container body-main"> <div> {% for section in section_list %} <p>{{ section }}</p> {% endfor %} </div> </div> <div> <nav aria-label="..."> <ul class="pager"> <li><a href="/blog/detail/{{ previous_article.article_id }}">Previous:{{ previous_article.title }}</a></li> <li><a href="/blog/detail/{{ next_article.article_id }}">Next:{{ next_article.title }}</a></li> </ul> </nav> </div> </body> </html>
我也是遇到了一样的问题 在内容显示判断里面加个判断 是否是最后一篇文章 再对内容进行查询
if article.article_id == article_id: if next_index == len(all_article): previous_article = all_article[(previous_index-1)] next_article = all_article[next_index-1] else: previous_article = all_article[previous_index] next_article = all_article[next_index] curr_article = article break
你是views.py文件里估计写的有点问题?
for index, article in enumerate(all_article): if index == 0: previous_index = index next_index = index + 1 else: previous_index = index - 1 next_index = index + 1 if article.article_id == article_id: curr_article = article previous_article = all_article[previous_index] next_article = all_article[next_index] break
看我这里加粗的部分!
三小时带你入门Django框架 新版上架
25629 学习 · 248 问题
相似问题