REST框架中的身份验证

REST框架中的身份验证

本文介绍了如何禁用Django REST框架中的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一家商店网站上工作,每个用户都将是匿名的(至少至少要付出代价),而我正在尝试使用Django REST框架来提供产品API,但是不断抱怨:

 详细信息:未提供身份验证凭据。 

我发现一些与身份验证相关的设置,但我找不到任何类似 ENABLE_AUTHENTICATION = True 。如何禁用身份验证,让访问者访问该API?

解决方案

您可以为和类。

  REST_FRAMEWORK = {
#其他设置...

'DEFAULT_AUTHENTICATION_CLASSES':[],
'DEFAULT_PERMISSION_CLASSES':[],
}


I'm working on a store site, where every user is going to be anonymous (well, until it's time to pay at least), and I'm trying to use Django REST Framework to serve the product API, but it keeps complaining about:

"detail": "Authentication credentials were not provided."

I found some settings related to authentication, but I couldn't find anything like ENABLE_AUTHENTICATION = True. How do I simply disable authentication, and let any visitor to the site access the API?

解决方案

You can give empty defaults for the permission and authentication classes in your settings.

REST_FRAMEWORK = {
    # other settings...

    'DEFAULT_AUTHENTICATION_CLASSES': [],
    'DEFAULT_PERMISSION_CLASSES': [],
}

这篇关于如何禁用Django REST框架中的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:47