Home > Blockchain >  Getting a 404 page not found, The current path, product/, matched the last one
Getting a 404 page not found, The current path, product/, matched the last one

Time:01-01

urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.product, name='products-page'),
    path('add-product', views.ProductAddView.as_view(), name='add-product'),
    path('<int:pk>/delete/', views.ProductDeleteView.as_view(), name='product-delete'),
    # path('product/<int:id>', views.product_detail, name='product-detail-page'),
    # path('product/<int:pk>', views.SingleProductView.as_view(), name='product-detail-page'),
    path('<int:pk>/', views.ProductUpdateView.as_view(), name='product-update'),
]

Views.py

def product(request):
    try:
        products_all = Product.objects.all()
        num_products = products_all.count()
        product_dict = {
            "data":products_all,
            "total": num_products
        }
        return render(request, 'products/product.html', context=product_dict)
    except:
        # Http404 will automatically look for a 404 html in templates
        raise Http404()

Seems to be something related to the query to the database. If I print the results to the console and remove the results from the context, the page loads.

CodePudding user response:

Thanks for the feedback. The issue was due to the fact that the template was using the get_absolute_url method in one of the links and I had commented out that url path and view. So the problem wasn't the actual template but an error in one of the links inside it.

  • Related