Getting "Page not found (404) No Product matches the given query." error

I've started getting this error after deleting all my products from my database (I did this because it was dummy data just for testing). When I runserver and go to localhost I see this error

The error states that this issue was raised in "home.views.index" despite the fact that the products are not called on the home page. I feel like my app is looking for the products and crashing when it cant find them.

here is the code for my app urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
     path('', include('home.urls')),
     path('admin/', admin.site.urls),
     path('products/', include('products.urls')),
     path('checkout/', include('checkout.urls')),
     path('bag/', include('bag.urls')),
     path('contact/', include('contact.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Here is my product/urls.py

from django.urls import path
from . import views
urlpatterns = [
     path('', views.all_products, name='products'),
     path('<int:product_id>/', views.product_detail, name='product_detail'),
]

Here is the code for products/views.py

from django.shortcuts import render
from .models import Product
def all_products(request):
    products = Product.objects.all()

    context = {
         'products': products,
 }

return render(request, "products/products.html", context )

def product_detail(request, product_id):
     product = get_object_or_404(Product, pk=product_id)

     context = {
        'product': product,
    }

return render(request, 'products/product_detail.html', context)

Any help you can offer is greatly appreciated and sorry if I'm missing some important information, comment what I'm missing and I will add it.

you should must add home.urls last

Or,

add other path in home.urls

urlpatterns = [
     # path('', include('home.urls')),
     path('admin/', admin.site.urls),
     path('products/', include('products.urls')),
     path('checkout/', include('checkout.urls')),
     path('bag/', include('bag.urls')),
     path('contact/', include('contact.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

**urlpatterns.append(path('', include('home.urls')))**
Вернуться на верх