Skip to content Skip to sidebar Skip to footer

Django Error ---index() Missing 1 Required Positional Argument: 'pk'

I have this error when try to open a path. It requires a pk in my def and i inserted it, but still the issue is there. If someone could help, i would owe you a lot! This is the err

Solution 1:

Include pk in your url.

Change your url like this,

url(r'(?P<pk>\d+)/$', views.index, name='index'),

instead of,

# /batches/

url(r'^$', views.index, name='index'),

OR,

if you are not passing pk to views then remove pk from index view as showned below.

defindex(request):
    all_Batches = Batches.objects.all()
    html = ''for batch in all_Batches:
        url = '/batches/' + str(batch.id) + '/'
        html += '<a href="#"' + url + '">' + str(batch.BatchNumber)+ '</a><br>'return  HttpResponse(html)

Solution 2:

There are two arguments for the index view. The URL that you have written only gives request. You must give pk as an input just like the detail URL

Solution 3:

Your url /batches/ has no parameter. So, Your index view should be

defindex(request):
   # ......

Post a Comment for "Django Error ---index() Missing 1 Required Positional Argument: 'pk'"