class Login(APIView):
SECRET =" demo"
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)
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"}),
error: type error json not 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+unsubscribe@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/c049370d-b1ae-453e-8f8a-0371a44752f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment