I use the django-rest-auth to generate the token to certificate my APIs, all I have configured fine in my project.
You see my snapshot top right corner, I have login my test01 account, using http://127.0.0.1:8000/rest-auth/login/(this is the django-rest-auth build-in link)
But when I access the url to KoleListAPIView, there comes out issue, says the request is AnonymousUser:
AttributeError at /api/userproducts/kole/list/
'AnonymousUser' object has no attribute 'openstackcloud_id'
Request Method: GET
Request URL: http://localhost:8000//api/userproducts/kole/list/
Django Version: 1.11.5
Exception Type: AttributeError
Exception Value:
'AnonymousUser' object has no attribute 'kole_id'
My views.py is bellow:
class KoleListAPIView(ListAPIView):
"""
list the Kole
"""
serializer_class = KoleListSerializer
def list(self, request, *args, **kwargs):
kole_id = self.request.user.kole_id # there comes the issue.
if kole_id == None:
return Response(data="please enter the password again", status=HTTP_511_NETWORK_AUTHENTICATION_REQUIRED, exception=Exception())
But I have login the test01 account.
And my REST_FRAMEWORK in settings:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES':[], #'rest_framework.permissions.IsAuthenticated'
'DEFAULT_AUTHENTICATION_CLASSES':['rest_framework.authentication.TokenAuthentication'],
'PAGE_SIZE':10
}
If I remove the 'rest_framework.authentication.TokenAuthentication' in the REST_FRAMEWORK of settings, its also this Error.

AnonymousUsererror?