class Login(APIView):
  
   def post(self, request, *args, **kwargs):
       import ipdb;ipdb.set_trace()
       username = request.POST.get('username')
       password = request.POST.get('password')
       user = Person.objects.get(username=username, password=password)
#        user = user[0]
       #import ipdb;ipdb.set_trace()
       if user:
           payload = {
               'id': user.pk,
               'username': user.username,
               'staff': user.email,
               'exp': datetime.utcnow()
           }
           token = {'token': jwt.encode(payload, self.SECRET)}
           return HttpResponse(
             json.dumps(token),
             content_type="application/json"
           )
       else:
           return HttpResponse(
             json.dumps({'Error': "Invalid credentials"}),
             status=400,
             content_type="application/json"
           )





I have written a login api which which should return the token if user is 
valid and then would save the same on client side.
But my api is getting this following error..


TypeError at /login/
 is not JSON serializable

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/de9cce42-7900-4455-ab35-b644575b6317%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to