Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django前页和下页_Python_Django - Fatal编程技术网

Python django前页和下页

Python django前页和下页,python,django,Python,Django,我用django在一个新闻网站上工作。 如何在上一篇文章和下一篇文章中获得文章的分类。 喜欢博客的页面。但是类型的ID在mysql中不是连续的 比如: 这通常是通过使用get\u next\u by\u FOO()功能实现的,该功能是 在您的模型中,您需要一个日期或日期时间字段: class Article(models.Model): date_published = models.DateTimeField() 然后,您可以在视图中获取下一个/上一个项目: next_pos

我用django在一个新闻网站上工作。 如何在上一篇文章和下一篇文章中获得文章的分类。 喜欢博客的页面。但是类型的ID在mysql中不是连续的

比如:


这通常是通过使用
get\u next\u by\u FOO()
功能实现的,该功能是

在您的模型中,您需要一个日期或日期时间字段:

class Article(models.Model):
    date_published = models.DateTimeField()
然后,您可以在视图中获取下一个/上一个项目:

    next_post = article.get_next_by_date_published()
    prev_post = article.get_previous_by_date_published()

它在django已经有一段时间了-1.5和1.6也有()
    next_post = article.get_next_by_date_published()
    prev_post = article.get_previous_by_date_published()