【问题标题】:CSRF verification failed Django-rest-framework DjoserCSRF 验证失败 Django-rest-framework Djoser
【发布时间】:2021-11-27 08:17:45
【问题描述】:

我在 Django-rest-framework 中有一个项目,使用基于 youtube 教程的 react spa Bryan Dunn - Web 开发视频 here。我在将其扩展到博客应用时遇到问题,因为我不断收到此错误。

#blog/view.py
class BlogListAPIView(ListCreateAPIView):
    serializer_class = BlogSerializer
    queryset = Blog.objects.all()


class BlogDetailAPIView(RetrieveUpdateDestroyAPIView):
    serializer_class = BlogSerializer
    queryset = Blog.objects.all()
    lookup_field = "id"

这是前端请求的问题吗?也许是一个丢失的标题或其他东西或后端?因为我在 Postman 和 YASG 中使用它没有问题。

【问题讨论】:

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


    【解决方案1】:

    我真的不知道如何在类视图中执行此操作,但如果您使用的是函数视图,则可以使用 csrf_exempt 装饰器 '从 django.views.decorators.csrf 导入 csrf_exempt' 然后 @csrf_exemot 定义你的函数() ......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      • 2012-09-08
      • 2015-06-02
      • 1970-01-01
      相关资源
      最近更新 更多