python - Override the authToken views in Django Rest -
i using token based authentication in django , need add user object in addition token being returned.
how override class view ? need add class , make changes ? found in rest_framework package , don't want modify library .
from rest_framework import parsers, renderers rest_framework.authtoken.models import token rest_framework.authtoken.serializers import authtokenserializer rest_framework.response import response rest_framework.views import apiview class obtainauthtoken(apiview): throttle_classes = () permission_classes = () parser_classes = (parsers.formparser, parsers.multipartparser, parsers.jsonparser,) renderer_classes = (renderers.jsonrenderer,) serializer_class = authtokenserializer print "dasdsa" def post(self, request): serializer = self.serializer_class(data=request.data) 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}) obtain_auth_token = obtainauthtoken.as_view()
you should extend customclass
authtoken
, route default url customclass
:
from rest_framework_jwt.views import obtainjsonwebtoken class jsonwebtokenapioverride(obtainjsonwebtoken): """ override jwt """ def post(self, request): # whatever want
then in urls.py
:
url( r'^api-auth$', cache_page(0)(views.jsonwebtokenapioverride.as_view()) )
i hope helps
Comments
Post a Comment