admin管理员组文章数量:1290959
I'm facing a strange issue with Django REST Framework (DRF).
# views.py
class CheckoutView(APIView):
permission_classes = [AllowAny]
def post(self, request, *args, **kwargs):
return Response({'total_price': 7879})
#url.py
urlpatterns = [
path("cart/checkout/<int:new>", checkoutView.as_view() , name="checkout"), # url 1
path("cart/checkout/", checkoutView.as_view() , name="checkout"), # url 2
]
issue :
if i hit with url 1 it gives response 200
if i hit url 2 it gives response 401 { "detail": "Authentication credentials were not provided." }
note that : 'permission_classes = [AllowAny]' is there in the view also i dont have defined default permission class in settings.py
I'm facing a strange issue with Django REST Framework (DRF).
# views.py
class CheckoutView(APIView):
permission_classes = [AllowAny]
def post(self, request, *args, **kwargs):
return Response({'total_price': 7879})
#url.py
urlpatterns = [
path("cart/checkout/<int:new>", checkoutView.as_view() , name="checkout"), # url 1
path("cart/checkout/", checkoutView.as_view() , name="checkout"), # url 2
]
issue :
if i hit with url 1 it gives response 200
if i hit url 2 it gives response 401 { "detail": "Authentication credentials were not provided." }
note that : 'permission_classes = [AllowAny]' is there in the view also i dont have defined default permission class in settings.py
Share Improve this question asked Feb 13 at 15:34 Irfan KIrfan K 112 bronze badges1 Answer
Reset to default 0There is a difference between authenticating and permissions. An APIView
has an .authentication_classes
[drf-doc] attribute as well, this determines how to check if a user has logged in. By default this has BasicAuthentication
and SessionAuthentication
.
Even if you thus don't need to have any permission, it will just run the authentication logic, and if there is for example a HTTP_AUTHORIZATION
header in the request, it needs to be formatted for example like basic username:password
.
You thus should look what authentication header you send to the view, and very likely it does not follow the right structure.
本文标签: Django DRF showing weired auth methode respective to URLStack Overflow
版权声明:本文标题:Django DRF showing weired auth methode respective to URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741520529a2383155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论