mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
ObtainAuthToken pluggable Serializer.
It should have serializer_class in the same way as any other API view.
This commit is contained in:
parent
ae139cb06f
commit
49cd5e59a8
|
@ -12,10 +12,11 @@ class ObtainAuthToken(APIView):
|
||||||
permission_classes = ()
|
permission_classes = ()
|
||||||
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
|
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
|
||||||
renderer_classes = (renderers.JSONRenderer,)
|
renderer_classes = (renderers.JSONRenderer,)
|
||||||
|
serializer_class = AuthTokenSerializer
|
||||||
model = Token
|
model = Token
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
serializer = AuthTokenSerializer(data=request.DATA)
|
serializer = self.serializer_class(data=request.DATA)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
token, created = Token.objects.get_or_create(user=serializer.object['user'])
|
token, created = Token.objects.get_or_create(user=serializer.object['user'])
|
||||||
return Response({'token': token.key})
|
return Response({'token': token.key})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user