我在Django-rest-framework中有一个项目,使用的是基于Bryan Dunn - Web Development Videos here的youtube教程的react spa。我在将它扩展到博客应用程序时遇到了问题,因为我一直收到这个错误。

#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"这是前端请求的问题吗?也许是一个已经丢失的头或者其他什么东西,或者在后端?因为我在邮递员和YASG中使用它没有问题。
发布于 2021-11-05 08:11:21
我真的不知道如何在类视图中做到这一点,但如果你使用的是函数视图,你可以使用csrf_exempt装饰器‘从django.views.decorators.csrf导入csrf_exempt’,然后使用@csrf_exemot定义your_function() ......
https://stackoverflow.com/questions/69477776
复制相似问题