title: No User matches a given query Django
body: <p>While trying to display post-detail template in a blog app, I get an error <code>No User matches a given query</code>. In my models I am inheriting from User model. What seems the problem?</p>
  <pre><code># Third party imports.
  from django.contrib.auth.models import User
  from django.db import models
  from django.urls import reverse
  from django.utils import timezone
  
  class Post(models.Model):
      &quot;&quot;&quot;
          Creates Model for a post in the database.
      &quot;&quot;&quot;
      title = models.CharField(max_length=100)
      sub_title = models.CharField(max_length=100)
      content = models.TextField()
      date_posted = models.DateTimeField(default=timezone.now)
      author = models.ForeignKey(User, on_delete=models.CASCADE)
  
      def __str__(self):
          &quot;&quot;&quot;
              A string representation of the post model.
          &quot;&quot;&quot;
          return self.title
  
      def get_absolute_url(self):
          &quot;&quot;&quot;
              Creates the absolute url for a particular post.
          &quot;&quot;&quot;
          return reverse('blog:post-detail', kwargs={'pk': self.pk})
  </code></pre>
  <p>views.py</p>
  <pre><code>class PostDetailView(DetailView):
      &quot;&quot;&quot;
          View for a post's details
      &quot;&quot;&quot;
      model = Post
      template_name ='blog/post_detail.html'
      context_object_name = 'posts'
      paginate_by = 3
  
  
      def get_queryset(self):
          user = get_object_or_404(User, username=self.kwargs.get('username'))
          return Post.objects.filter(author=user).order_by('-date_posted')
  </code></pre>
  <p>urls.py:</p>
  <pre><code># Third party imports.
  from django.urls import path
  from .views import (
      PostListView,
      PostDetailView,
      PostCreateView,
      PostUpdateView,
      PostDeleteView,
      UserPostListView,
  )
  
  # Local application imports.
  from . import views
  
  # Specifies the app's name.
  app_name = &quot;blog&quot;
  
  urlpatterns = [
      path('', PostListView.as_view(), name='home'),  # url for post list.
      path('user/&lt;str:username&gt;/',
           UserPostListView.as_view(),
           name='user-posts'),  # url for specific user post.
      path('post/&lt;int:pk&gt;/',
           PostDetailView.as_view(),
           name='post-detail'),  # url for post detail.
      path('post/new/',
           PostCreateView.as_view(),
           name='post-create'),  # url to create new post.
      path('post/&lt;int:pk&gt;/update/',
           PostUpdateView.as_view(),
           name='post-update'),  # url to update post.
      path('post/&lt;int:pk&gt;/delete/',
           PostDeleteView.as_view(), name='post-delete'),  # url to delete post.
      path('about/', views.about, name='about'),  # url for about page.
  ]
  </code></pre>
  <p>home.html</p>
  <pre><code>{% extends 'blog/base.html' %}
  {% load static %}
  {% block crumb %}
  {% for post in posts %}
  &lt;div class=&quot;post-preview&quot;&gt;
  &lt;a href=&quot;{% url 'blog:post-detail' post.id %}&quot;&gt;
  &lt;h2 class=&quot;post-title&quot;&gt;{{ post.title }}   &lt;/h2&gt;
  &lt;h3 class=&quot;post-subtitle&quot;&gt;{{ post.sub_title }}  &lt;/h3&gt;
  &lt;/a&gt;
  
  &lt;p class=&quot;post-meta&quot; style=&quot;font-weight: 300;&quot;&gt; Posted by 
    &lt;a class=&quot;text-muted&quot;&gt;{{post.author}} on {{ post.date_posted|date:&quot;F d, Y&quot; }}&lt;/a&gt;
    
  &lt;/p&gt;
  
  &lt;/div&gt;
  &lt;hr class=&quot;my-4&quot; /&gt;
  {% endfor %}
  
  {% endblock %}
  </code></pre>
  <p>post_detail.html</p>
  <pre><code>{% extends &quot;blog/base.html&quot; %}
  {% block content %}
    &lt;article class=&quot;media content-section&quot;&gt;
      &lt;img class=&quot;rounded-circle article-img&quot;
           src=&quot;{{ object.author.profile.image.url }}&quot;&gt;
      &lt;div class=&quot;media-body&quot;&gt;
        &lt;div class=&quot;article-metadata&quot;&gt;
          &lt;a class=&quot;mr-2&quot;
             href=&quot;{% url 'blog:user-posts' object.author.username %}&quot;&gt;{{ object.author }}
          &lt;/a&gt;
          &lt;small class=&quot;text-muted&quot;&gt;{{ object.date_posted|date:&quot;F d, Y&quot; }}&lt;/small&gt;
          {% if object.author == user %}
            &lt;div&gt;
              &lt;a class=&quot;btn btn-secondary btn-sm mt-1 mb-1&quot;
                 href=&quot;{% url 'blog:post-update' object.id %}&quot;&gt;Update
              &lt;/a&gt;
              &lt;a class=&quot;btn btn-danger btn-sm mt-1 mb-1&quot;
                 href=&quot;{% url 'blog:post-delete' object.id %}&quot;&gt;Delete
              &lt;/a&gt;
            &lt;/div&gt;
          {% endif %}
        &lt;/div&gt;
        &lt;h2 class=&quot;article-title&quot;&gt;{{ object.title }}&lt;/h2&gt;
        &lt;p class=&quot;article-content&quot;&gt;{{ object.content }}&lt;/p&gt;
      &lt;/div&gt;
    &lt;/article&gt;
  {% endblock content %}
  </code></pre>