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 also apply it on one specific endpoint by applying it on class or method. Just need to apply django rest framework AllowAny permission to the specific method or class.
views.py
You can achieve the same result by using an empty list or tuple for the permissions setting, but you may find it useful to specify this class because it makes the intention explicit.
You can give empty defaults for the permission and authentication classes in your settings.
If using APIView you can create a permission for the view, example below:
urls.py
permissions.py
views.py
You can also disable authentication for particular class or method, just keep blank the decorators for the particular method.