In file ==> category_posts = Post.object.filter(category=cat) returns an empty query set. The 'Post' model has sample posts with categories

I am creating a blog application in django where i encountered this unusual issue. I am not being able to filter and display blog posts category wise. Please find my code below. Thanks in advance. I have spent two full days trying to figure this out and still got nothing.

This is the model which i have created for a blog post.

class Post(models.Model):
    title = models.CharField(max_length=255)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    body = models.TextField()
    post_date = models.DateField(auto_now_add=True)
    category = models.CharField(max_length=255, default="uncategorized")

    def __str__(self):
        return self.title + ' | ' + str(

    def get_absolute_url(self):
        #return reverse('article-detail', args=(str(
        return reverse('homepage')

This is the view that i have created for a category wise blog posts.

def CategoryView(request,cat):
    category_posts = Post.objects.filter(category=cat)
    return render(request,'categories.html',{'category_posts':category_posts})

The file.

path('category/<str:cat>/', CategoryView, name = 'category'),


This will be the final display page where the category_posts is displayed as an empty queryset. The for loop is unable to run because category_posts is an empty queryset. Single word categories are also empty(to rule out a slugify issue)

{% extends 'base.html' %}
{% load static %}
{% block content %}

{% for post in category_posts %}
    <div class="category">
      <a href="{% url 'category' post.category|slugify %}">{{ post.category }}</a>
    <a href="{% url 'article-detail'  %}">
      <h3><b>{{ post.title }} </b></h3>
      <p class=card-date>
        <big>{{ }}</big>
        <small>-{{ post.post_date }}</small>
      <p class="excerpt-text">{{ post.body | slice:"100" |safe}}</p>
      <div class="article-thumbnail">
         <img src="{% static "images/bg.png" %}" alt="article-thumbnail" >
     <div class="overlay">
{% endfor %}

{% endblock %}
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum