1👍
✅
One way you can handle this is to use .get_previous_by_Foo and .get_next_by_Foo
you can read more here : https://docs.djangoproject.com/en/2.1/ref/models/instances/#django.db.models.Model.get_next_by_FOO
This is just an idea how you can do it.
{% extends "blogs/base.html" %}
{% load static %}
{% block post %}
<section class="services">
<dev class="box-container">
<div class="box-lg">
<h3>{{ post.title }}</h3>
<img src="/Images/{{ post.cover }}" >
<hr>
<small>{{ post.published_at }}</small>
<p>{{ post.content | safe }}</p>
</div>
</dev>
</section>
<!-- Pagination Start -->
<div class="center">
{{ post.get_previous_by_published_at.title }}
</div>
<!-- Pagination Ends -->
<div class="center">
{{ post.get_next_by_published_at.title }}
</div>
{% endblock post %}
as i said this just an idea in real life you have to check that next or previous post exists or maybe that post is the last one a thing like that…
Source:stackexchange.com