Search code examples
pythondjango

How to store django objects as session variables ( object is not JSON serializable)?


I have a simple view

def foo(request):
   card = Card.objects.latest(datetime)
   request.session['card']=card

For the above code I get the error

"<Card: Card object> is not JSON serializable"

Django version 1.6.2. What am I doing wrong ?


Solution

  • @Martijn is or might be the correct way to save the object in session variables.

    But the issue was solved by moving back to Django 1.5. So this issue is specifically for django 1.6.2.

    Hope this helps.