I made a serializer, and view to override the set_password, but got the error:
ImportError: cannot import name 'SetPasswordView' from 'djoser.views'
here is serializer:
class CustomSetPasswordSerializer(SetPasswordSerializer):
def validate(self, attrs):
attrs = super().validate(attrs)
attrs["message"] = "Your password has been changed successfully."
return attrs
Djoser settings:
DJOSER = {
'USER_ID_FIELD': 'username',
'USER_CREATE_PASSWORD_RETYPE': True,
'PASSWORD_RESET_CONFIRM_RETYPE': True,
'SET_PASSWORD_RETYPE': True,
'SERIALIZERS': {
'user_create': 'accounts.serializers.UserCreateSerializer',
'user': 'accounts.serializers.UserCreateSerializer',
'set_password': 'accounts.serializers.CustomSetPasswordSerializer',
},
}
from djoser.views import SetPasswordView
from rest_framework.response import Response
class CustomSetPasswordView(SetPasswordView):
serializer_class = CustomSetPasswordSerializer
def action(self, serializer):
self.request.user.set_password(serializer.data["new_password"])
self.request.user.save()
return Response({"message": serializer.data["message"]})
I need when make a request to set_password, return a response with a message
attrs["message"] = "Your password has been changed successfully.
Now the response is 204 No content