I've created rest APIs using Django-rest-auth, in login, it's returning key and some user info, But I need to add some status like success and message and some other things. Is there any way to override view of django-rest-auth for login?
class TokenSerializer(serializers.ModelSerializer):
user = UserSerializer(many=False, read_only=True) # this is add by myself.
device = DeviceSerializer(many=True, read_only=True)
class Meta:
model = TokenModel
fields = ('key', 'user', 'device',)
Basic Authentication in Django REST Framework uses HTTP Basic Authentication. It is generally appropriate for testing. The REST framework will attempt to authenticate the Basic Authentication class and set the returned values to request. user and request.
Create a custom view class and use it
from rest_auth.views import LoginView
class CustomLoginView(LoginView):
def get_response(self):
orginal_response = super().get_response()
mydata = {"message": "some message", "status": "success"}
orginal_response.data.update(mydata)
return orginal_response
and change your urls.py
as
urlpatterns = [
url(r'custom/login/', CustomLoginView.as_view(), name='my_custom_login')
]
now you should use the endpoint /custom/login/
instead of /rest-auth/login
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With