Reputation: 113
I'm trying to use rest_framework.authtoken I'm following this instructions https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication
but whenever i try to do python manage.py migrate
authtoken.Token.user: (fields.E300) Field defines a relation with model 'auth.User', which is either not installed, or is abstract.
authtoken.Token.user: (fields.E307) The field authtoken.Token.user was declared with a lazy reference to 'auth.user', but app 'auth' isn't installed.
this error happens
I red error message and thought that I need to install "auth"
so I pip install django-rest-auth
but it didn't work
and this is my part of my settins.py
INSTALLED_APPS = [
'rest_auth',
'rest_framework.authtoken',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}
it is views.py (i'm working on it so itis not completed)
@api_view(http_method_names=['POST'])
@permission_classes([AllowAny])
@psa()
def exchange_token(request, backend):
serializer = UserSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
user = request.backend.do_auth(serializer.validated_data['access_token'])
if user:#drf built in token authentication??
token, _ = Token.objects.get_or_create(user=user) # drf token authentication
return Response({'token':token.key})
else:
return Response(
{'errors':{'token':'Invalid token'}},
status = status.HTTP_400_BAD_REQUEST,
)
I'm trying to do this to use that "Token.objects~~"
there is no migration file i can fix.. documents just told me to do python manage.py migrate
anyone please inform me what is wrong..
Upvotes: 1
Views: 282