title: No Product matches the given query. Django
body: <p>I created <code>BlogPost</code> class. Then created ListView <code>BlogPostListView</code> and <code>blogpost_detail</code>.</p>
  <p><strong>ADDED diff off all change that affected error</strong> -- <a href="https://pastebin.com/DyukCYq9" rel="nofollow noreferrer">https://pastebin.com/DyukCYq9</a></p>
  <p>When I clicked to post name (on this page <a href="https://edamer.ru/blog_posts/" rel="nofollow noreferrer">https://edamer.ru/blog_posts/</a>)</p>
  <p>I was redirected to the valid url. But I received error instead product_detail page:</p>
  <blockquote>
  <p>Page not found. <a href="http://127.0.0.1:8001/blog_post/1/" rel="nofollow noreferrer">http://127.0.0.1:8001/blog_post/1/</a></p>
  </blockquote>
  <blockquote>
  <p>Raised by:    blog.views.product_detail. No Product matches the given query.</p>
  </blockquote>
  <p>I can't understand why <code>product_detail()</code> called instead of <code>blogpost_detail()</code>
  Also error text said about <strong>Product</strong> (<strong>Product</strong> - is name of another model in my app. But I was calling <code>BlogPost</code> (not Product)</p>
  <p><strong>I tried</strong></p>
  <ol>
  <li>python manage.py flush # clear database</li>
  <li>Review my changes. But did not find calls of  <code>product_detail()</code></li>
  </ol>
  <p><strong>I think that error deals with invalid urls</strong></p>
  <p><strong>My code</strong></p>
  <p><strong>views.py</strong></p>
  <pre><code>def product_detail(request, **kwargs):
      product = get_object_or_404(Product, pk=kwargs[&quot;pk&quot;])
      shops = Shop.objects.all()
      return render(request, 'blog/product_detail.html', {'product': product, 'shops': shops})
  
  
  class BlogPostListView(ListView):
      model = BlogPost
      template_name = 'blog/post_list.html'
      page_kwarg = 'blog_post'
      context_object_name = 'blog_posts'
  
  
  def blogpost_detail(request, **kwargs):
      post = get_object_or_404(BlogPost, pk=kwargs[&quot;pk&quot;])
      return render(request, 'blog/post_detail.html', {'post': post})
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>urlpatterns = [
      path('', HomePageView.as_view(), name='main_list'),
      path('search/', SearchResultsView.as_view(), name='search_results'),
      path('search_shop/&lt;slug:slug&gt;/', ProductListView.as_view(), name='search_shop'),
      path('search_shop_results/&lt;slug:slug&gt;/', ProductSearchResultsView.as_view(), name='search_shop_results'),
      path('&lt;slug:slug&gt;/&lt;int:pk&gt;/', views.product_detail, name='product_detail'),
  
      path('shops/', ShopListView.as_view(), name='shop_list'),
      path('contacts/', views.contacts, name='contacts'),
  
      path(&quot;robots.txt&quot;, TemplateView.as_view(template_name=&quot;blog/robots.txt&quot;, content_type=&quot;text/plain&quot;)),
      url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
      url(r'^favicon\.ico$', RedirectView.as_view(url='/static/favicon.ico'), name='favicon'),
  
      path('register/', views.RegisterFormView.as_view(), name=&quot;register&quot;),
      path('login/', views.LoginFormView.as_view(), name=&quot;login&quot;),
      path('logout/', views.LogoutView.as_view(), name=&quot;logout&quot;),
  
      path('blog_posts/', views.BlogPostListView.as_view(), name='post_list'),
      path('blog_post/&lt;int:pk&gt;/', blogpost_detail, name='blogpost_detail'),
  ]
  </code></pre>
  <p><strong>post_list.html</strong></p>
  <pre><code>{% for post in blog_posts %}
          &lt;a href=&quot;{% url 'blogpost_detail' post.pk %}&quot; style=&quot;text-decoration: none;color:inherit;&quot;&gt;
              {{post.title}}
          &lt;/a&gt;
          &lt;p&gt;{{post.prev_text}}&lt;/p&gt;
          &lt;br&gt;
  {% endfor %}
  </code></pre>
  <p><strong>post_detail.html</strong></p>
  <pre><code>&lt;h1&gt;Post detail&lt;/h1&gt;
  
  &lt;div class=&quot;container&quot; style=&quot;margin-top: 40px; font-size: 1.2rem; padding-left: 0px;&quot;&gt;
      &lt;h1&gt;{{post}}&lt;/h1&gt;
  &lt;/div&gt;
  </code></pre>