Django “get() got an unexpected keyword argument 'pk'” error

后端 未结 3 720
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 19:08

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

           


        
相关标签:
3条回答
  • 2020-12-30 19:42

    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.

    0 讨论(0)
  • 2020-12-30 19:54

    add the kwargs into the method definition:

    def get(self, request, *args, **kwargs):
        return HttpResponse("Created :)")
    
    0 讨论(0)
  • 2020-12-30 19:54

    Check that if your views.fun_name is same as the function name in views

    0 讨论(0)
提交回复
热议问题