405 “Method POST is not allowed” in Django REST framework

前端 未结 4 1901
暖寄归人
暖寄归人 2021-01-04 07:15

I am new in Django REST framework. Can someone explain why I get such error, if I make a POST request to \'/api/index/\'

405 Method Not Allowed
{\"detail\":\         


        
4条回答
  •  长发绾君心
    2021-01-04 07:50

    Make sure that you have "POST" in http_method_names. Alternatively, you can write it like this:

    def allowed_methods(self):
        """
        Return the list of allowed HTTP methods, uppercased.
        """
        self.http_method_names.append("post")
        return [method.upper() for method in self.http_method_names
                if hasattr(self, method)]
    

提交回复
热议问题