CustomAuthToken

63 views
Skip to first unread message

shubham joshi

unread,
Aug 1, 2019, 11:17:16 PM8/1/19
to Django users
With reference to the documentation, https://www.django-rest-framework.org/api-guide/authentication/#how-authentication-is-determined 
I was trying to use CustomAuthToken, in my app view and import it in url


from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response

class CustomAuthToken(ObtainAuthToken):

    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data,
                                           context={'request': request})
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        token, created = Token.objects.get_or_create(user=user)
        return Response({
            'token': token.key,
            'user_id': user.pk,
            'email': user.email
        })
But it giving circular import error
my project without customAuth - https://github.com/shubham1507/school/blob/master/users/views.py


Reply all
Reply to author
Forward
0 new messages