I am new in Django
I have this function in views.py
def edituser(request, id):
member = User.objects.get(id=id)
return JsonResponse(member, safe=False)
i have the error: Object of type User is not JSON serializable
How can i solve to return User values to javascript ajax function ?
2
Answers
I think that the answer is here: https://linuxpip.org/object-of-type-is-not-json-serializable/ since the User object IS and/or contains non-serializables values, let’s call them "this object contains a thing that have not a Javascript equivalent" check if you have an attribute out of the table in the link provided, to solve this maybe you should filter the "User" object using
json.JSONEncoder
If you know the attributes that you want to return from the User object, you could construct a dictionary of those specific attributes: