【问题标题】:password_reset_confirm, sensitive_post_parameters didn't receive an HttpRequestpassword_reset_confirm,sensitive_post_parameters 没有收到 HttpRequest
【发布时间】:2015-07-21 23:10:39
【问题描述】:

我正在使用DRF 编写密码重置功能,

一切正常,但我收到此错误:

Django Version: 1.8.3
Exception Type: AssertionError
Exception Value:    
sensitive_post_parameters didn't receive an HttpRequest. If you are decorating a classmethod, be sure to use @method_decorator.

这是代码启动错误:

class RecoveryPasswordConfirm(APIView):
    """
    API endpoint for recovery password
    """
    serializer_class = UpdatePasswordUserSelializer
    permission_classes = (AllowAny, )

    def post(self, request, uidb64=None, token=None):
        response = password_reset_confirm(
            request,
            template_name='',
            uidb64=uidb64,
            token=token,
            post_reset_redirect=reverse('password_reset_done'))

        return Response({}, status=status.HTTP_200_OK)

我不知道我应该做更多。

谢谢。

【问题讨论】:

  • 您是否记得将urls.py 中的视图设置为RecoveryPasswordConfirm.as_view()
  • @KevinBrown 是的,当使用 post 请求调用 RecoveryPasswordConfirm 时捕获它,但 password_reset_confirm 返回错误

标签: django django-rest-framework django-authentication


【解决方案1】:

我没有看到您的代码中使用了sensitive_post_parameters,它应该在password_reset_confirm 中的某个位置。

最有可能的问题是因为 DRF 使用它自己的请求类来包装 django 期望的原始 HttpRequest。 见more details here

尝试使用request._request传递原始django请求。

response = password_reset_confirm(
    request._request,

【讨论】:

  • request._request 工作,谢谢。及时!再次感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 2021-05-22
  • 2021-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多