Can not put more parameters in post Django
I have a problem I gets an error post() missing 1 required positional argument: 'pk'
.
It occured when I added slug into it. Is there any workaround? I would appreciate any kind of help.
def post(self, request, pk, username, slug):
if 'delete' in self.request.POST:
Item.objects.get(id=pk).delete()
print('deleted')
return redirect('home-page')
if 'add' in self.request.POST:
form = ItemCreationForm(self.request.POST)
if form.is_valid():
form.save()
name = form.cleaned_data.get('itemName')
item = Item.objects.create(itemName=name)
card = Card.objects.get(user=self.request.user, slug=self.kwargs.get('slug'))
card.cardItems.add(item)
return redirect('todo-page', username=self.request.user.username, slug=self.kwargs.get('slug'))
urls.py
path('', Home.as_view(), name='home-page'),
path('todo/<str:username>/<slug:slug>', TodoView.as_view(), name='todo-page'),
path('sign-up', Signup.as_view(), name="sign-up-page"),
path('logout', views.logout_view, name='logout-page'),
path('login', views.loginView, name='login-page'),
path('profile/<str:pk>', ProfileView.as_view(), name='profile-page')
*added urls
It's because your url is not prepared to receive pk, you need to do something like
path('todo/<int:pk>/<str:username>/<slug:slug>', TodoView.as_view(), name='todo-page')