request.session[SESSION_KEY] = user._meta.pk.value_to_string(user) AttributeError: 'str' object has no attribute '_meta'
时间: 2024-02-09 10:09:12 浏览: 145
这个错误通常是由于在保存用户会话时,使用了一个字符串类型的对象而不是一个用户对象。在Django中,session中存储的用户通常是一个User对象,而不是一个字符串。因此,你需要检查一下你的代码,确保在保存用户会话时使用了正确的对象类型。你可以使用Django提供的get_user_model()方法来获取正确的用户模型,例如:
```
from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username='your_username')
request.session['user_id'] = user.id
```
这样,你就可以在会话中存储正确的用户对象了。
阅读全文
相关推荐


















