# How can I paginate my posts list in my homepage blog?

**URL:** <https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961>\
**Category:** Forms & APIs\
**Created:** [April 2, 2022, 11:59am UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961 "2022-04-02T11:59:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sajadhn1988](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sajadhn1988/32/8003_2.png) [@sajadhn1988](https://forum.djangoproject.com/u/sajadhn1988)\
**Post date:** [April 2, 2022, 11:59am UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/1 "2022-04-02T11:59:12Z")

</div>

```auto
#view.py---------------------------------------------------------------------------------------------------------------------
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from .models import Post, Category, Comment
from .forms import PostForm, EditForm, CommentForm
from django.urls import reverse_lazy, reverse
from django.http import HttpResponseRedirect

#Import Pagination Stuff
from django.core.paginator import Paginator

class HomeView(ListView):
	# paginate_by = 5
	model = Post
	template_name = 'home.html'
	cats = Category.objects.all()
	#ordering = ['-post_date']
	ordering = ['-id']

	def get_context_data(self, *args, **kwargs):
		cat_menu = Category.objects.all()
		context = super(HomeView, self).get_context_data(*args, **kwargs)
		context["cat_menu"] = cat_menu
		return context

```

home.html-----------------------------------------------------------------------------------------------------------------------

{% extends ‘base.html’ %}

{% block content %}

# Posts

{% for post in object\_list %} - {{ post.title }}

```
	- <a href="{% url 'category' post.category|slugify %}">{{ post.category }}</a>
	- {{ post.author.first_name }} {{ post.author.last_name }} -  
	{{ post.post_date }} <small>

	{% if user.is_authenticated %}	
		{% if user.id == post.author.id %}
			- <a href="{% url 'update_post' post.pk %}">(Edit)</a> 

			<a href="{% url 'delete_post' post.pk %}">(Delete)</a>
		{% endif %}
	{% endif %}

</small> <br/>
{{ post.snippet }}</li>

```

{% endfor %}

{% endblock %}

---

<div class="post-metadata">

**Author:** ![plopidou](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/plopidou/32/5148_2.png) [@plopidou](https://forum.djangoproject.com/u/plopidou)\
**Post date:** [April 2, 2022, 12:10pm UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/2 "2022-04-02T12:10:30Z")

</div>

```auto
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

category_queryset = Category.objects.all()
category_paginator = Paginator(category_queryset, 10)

page = 1
try:
    categories = category_paginator.page(page)
except PageNotAnInteger:
    categories = category_paginator.page(1)
 except EmptyPage:
    categories = category_paginator.page(category_paginator.num_pages)

context['categories'] = categories

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 2, 2022, 2:08pm UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/3 "2022-04-02T14:08:32Z")

</div>

See the docs at [Django Pagination](https://docs.djangoproject.com/en/4.0/topics/pagination/#pagination) for details on using the Paginator, especially [the section on Paginating a ListView](https://docs.djangoproject.com/en/4.0/topics/pagination/#paginating-a-listview).

---

<div class="post-metadata">

**Author:** ![sajadhn1988](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sajadhn1988/32/8003_2.png) [@sajadhn1988](https://forum.djangoproject.com/u/sajadhn1988)\
**Post date:** [April 2, 2022, 3:37pm UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/4 "2022-04-02T15:37:38Z")

</div>

Thank you, sir. But what I have tried so far wasn’t successful. could you give me some points on how can I make it work?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 2, 2022, 3:53pm UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/5 "2022-04-02T15:53:08Z")

</div>

Please post the view you are using and the associated template that matches the pattern as shown in the doc, and we can help identify where the issues may be. Remember to enclose _both_ the template _and_ the view between lines of three backtick - ` characters.

---

<div class="post-metadata">

**Author:** ![sajadhn1988](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sajadhn1988/32/8003_2.png) [@sajadhn1988](https://forum.djangoproject.com/u/sajadhn1988)\
**Post date:** [April 2, 2022, 4:36pm UTC](https://forum.djangoproject.com/t/how-can-i-paginate-my-posts-list-in-my-homepage-blog/12961/6 "2022-04-02T16:36:33Z")

</div>

[this is the link to the complete project from github](https://github.com/flatplanet/djangoblog.git)
