【问题标题】:"detail": "You do not have permission to perform this action.""detail": "您无权执行此操作。"
【发布时间】:2021-09-30 07:43:42
【问题描述】:

    class ProductViewSet(viewsets.ModelViewSet):
       queryset = ProductInfo.objects.all().order_by('-id')
       serializer_class = ProductSerializer
       permission_classes = [IsAdminUser]
       authentication_classes = []
       filter_backends = (filters.SearchFilter,)
       search_fields = ['title','code','owner__username']

大家好!我尝试使用 DRF 和邮递员获取我的产品列表...我尝试了几次,但我得到了一个错误,就像我说的那样。我的authentication_classes 是默认的TokenAuthentication,我有权限类..这个错误是为了我的权限 PLZ帮帮我。谢谢

我想我需要在这里做点什么。

【问题讨论】:

  • 你能发布相关的DRF代码吗?
  • 当然。我添加了...
  • 你看到这篇文章了吗?看起来很相似。 stackoverflow.com/questions/58151021/…。看起来TokenAuthentication authentication_class 是显式设置的,即使它是authentication_classes 默认值。你可以试试看。
  • 感谢您的回答,但现在我得到“详细信息”:“未提供身份验证凭据。”
  • 嗯,我不知道,抱歉。我只能说确保在 Postman 中选择了“授权”,并确保令牌根据 Django rest 框架文档以正确的格式写入,即“令牌 0390a72cadc ....”。否则,据我所知,一切看起来都不错。

标签: django-rest-framework permissions postman


【解决方案1】:

您需要在标题中添加AuthorizationToken 关键字,如

Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b

https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    相关资源
    最近更新 更多