我使用Django并试图显示发布数据的人的详细信息。所以基本上显示了发布中定义的“thing”的人的用户名模型.py在
在视图.py我在尝试:
def thing_detail_view(request, pk):
thing_detail = Thing.objects.get(pk=pk)
user = User.objects.get(request.user)
return render(request, 'thing_detail.html', {'thing_detail': thing_detail, 'user': user})
Im收到错误:
'User' object is not iterable
但我知道我不应该使用请求.用户因为这基本上是指正在进行当前会话或当前登录的用户。你知道我怎样才能得到发布了特定pk数据的用户的用户名并在html中显示吗?在
我想你应该用
userId = thing_detail.userId
代替request.user
userId
可以是用户模型的原始密钥相关问题 更多 >
编程相关推荐