[Django]-TypeError: post() got an unexpected keyword argument 'slug'

5👍

You should add slug as method argument also:

def post(self, request, slug):
    return render(request, self.template_name)

You need to pass context to the template as well:

def post(self, request, slug):
    self.object = self.get_object()
    context = self.get_context_data(object=self.object)
    return render(request, self.template_name, context=context)

But actually since your post doesn’t add specific logic to the view you can just call super:

def post(self, request, slug):
    return super().post(request, slug)

Or simply remove post method completely cause it’s redundant.

Leave a comment