如何将django对象存储为会话变量(对象不是JSON可序列化的)?
问题描述:
我有一个简单的看法
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版本1.6.2.我究竟做错了什么 ?
Django version 1.6.2. What am I doing wrong ?
答
@Martijn是或可能是将对象保存在会话变量中的正确方法.
@Martijn is or might be the correct way to save the object in session variables.
但是通过移回Django 1.5解决了该问题.因此,此问题专门针对Django 1.6.2.
But the issue was solved by moving back to Django 1.5. So this issue is specifically for django 1.6.2.
希望这会有所帮助.