简体   繁体   English

Django Rest Framework-对于用户注册,获取身份验证错误

[英]Django Rest Framework - For user registration getting authentication error

I am registering the user by using this post , In this case successfully i am creating the user. 我正在使用此帖子注册用户,在这种情况下,我正在成功创建用户。

After above step, I enabled token authentication by using this post , but the main problem is when i perform registration operation it is showing "detail": "Authentication credentials were not provided." 完成上述步骤后,我通过使用此文章启用了令牌身份验证,但是主要问题是当我执行注册操作时显示“详细信息”:“未提供身份验证凭据。” this error. 这个错误。

Here i don't need authentication checking for user registration, need authentication checking for remaining apis. 在这里,我不需要用户注册的身份验证检查,也不需要其余API的身份验证检查。

Can anyone please help me out how to disable authentication for user registration. 谁能帮我解决如何禁用用户注册的身份验证。

Thanks in advance 提前致谢

Depending on how you want your endpoint to be accessed and the level of publicity you can use 1 of 2 permissions. 根据您希望访问端点的方式以及公开程度,可以使用2个权限之一。

Either AllowAny or IsAuthenticatedOrReadOnly AllowAnyIsAuthenticatedOrReadOnly

AllowAny will allow for anyone accessing each of the methods you've defined for the viewset. AllowAny将允许任何人访问您为视图集定义的每个方法。

IsAuthenticatedOrReadOnly will, by default, allow anyone to use the safe http methods GET , HEAD or OPTIONS on your endpoint but in order to POST , PUT/PATCH or DELETE you would need to be authenticated. 默认情况下, IsAuthenticatedOrReadOnly允许任何人在您的端点上使用安全的http方法GETHEADOPTIONS ,但是要进行POSTPUT/PATCHDELETE ,则需要进行身份验证。

You add these to each of your endpoints for fine grained control 您将它们添加到每个端点,以进行细粒度的控制

from rest_framework import permissions

class MyViewSet(viewsets.GenericViewSet):
    permissions_classes = (permissions.AllowAny, )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM