Django Broken pipe from ('127.0.0.1', 49903)

enter code hereI got this error when I passed an id in the URL. Please check my below code.

  • href url

  • urls

    from django.contrib import admin from django.urls import path from he_admin import views

    app_name='he_admin' urlpatterns = [ path('',views.index,name='index'), path('addproductscategory',views.add_products_category,name='addcategory'), path('showcategories',views.ShowCategory,name='showcategories'), path('view/int:pk',views.ViewCategory,name='viewcategory'),

    ]

  • view function

    def ViewCategory(request, pk): try: category=ProductCategory.objects.get(id=pk) except: raise Http404('category does not exist') return render(request,"viewcategory.html",{"category":category})

error

error image

Not sure if it would raise the same error, but there is an issue with the definition of this URL:

path('view/int:pk',views.ViewCategory,name='viewcategory'

The PK part is not specified well. Try this:

path('view/<int:pk>',views.ViewCategory,name='viewcategory'
Back to Top