django - Unabe to get token from DRF get-token api -
my custom signup api
from rest_framework import viewsets rest_framework import serializers class signupserializer(serializers.serializer): email = serializers.emailfield(required=true) password = serializers.charfield(required=true, write_only=true) def validate_email(self, val): try: user.objects.get(username=val) raise serializers.validationerror("email-id exist") except user.doesnotexist: return val class signupview(viewsets.modelviewset): serializer_class = signupserializer def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=true) data = serializer.data email = data.get('email') password = data.get('password') u = user(email=email, username=email) u.set_password(password) u.save() data = { 'message': 'successfully created!', 'data': {'id': u.id, 'email': email}, } return response(data)
toekn api
from rest_framework.authtoken import views urlpatterns = [ url(r'^api-token-auth/', views.obtain_auth_token), ]
when hit signup
api, returns success response, mean
{ 'message': 'successfully created!', 'data': {'id': 1, 'email': 'xyz@gmail.com'} }
but when try generate/get token user using above token api, says ..invalid credentials?
{ "non_field_errors": [ "unable log in provided credentials." ] }
however if create user using management command createsuperuser , use same api token works?
is there someting wrong in signup api?
you should remove write_only=true
serializer. fix error.
Comments
Post a Comment