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

后端 未结 3 729
没有蜡笔的小新
没有蜡笔的小新 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.

提交回复
热议问题