class Book(models.Model):
author = models.ForeignKey(User)
name = models.CharField(max_length=100)
def view(request):
book = Book.objects.get(pk=1)
request.session['selected_book'] = book
将对象存储在 Session 而不是它们的 id 是一种好习惯吗?
例如,它是否足够“可腌制”以在模板中使用?
<div>{{ request.session.book.author.name }}</div>