I am trying to redirect to a page I intend to implement as an object's homepage after creation of one.
Below is corresponding part of my views.py
new_station_object.save()
return HttpResponseRedirect(reverse("home_station",
kwargs={'pk': new_station_object.id}
))
class StationHome(View):
def get(self, request):
return HttpResponse("Created :)")
and corresponding part of my urls.py;
url(r'^station/(?P<pk>\d+)$', StationHome.as_view(), name='home_station'),
But I get the said error;
TypeError at /station/2
get() got an unexpected keyword argument 'pk'
Someone please help me out.
The function is getting one argument more than it is supposed to. Change it to:
def get(self, request, pk):
The value of pk will be equal to the pattern that has been matched, and since you've specified that it's going to be a number, the type of pk will be int.
add the kwargs into the method definition:
def get(self, request, *args, **kwargs):
return HttpResponse("Created :)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With