Python 头Django中的奇怪用户配置文件数据
我试图做的是,在标题中,当我在菜单中输入一个非我自己的配置文件时,该用户的数据显示在标题中。但当我进入时间线时,我的数据就出来了。这是我的密码 models.py(Perfil) views.py(Perfil): header.html(片段):Python 头Django中的奇怪用户配置文件数据,python,django,user-profile,Python,Django,User Profile,我试图做的是,在标题中,当我在菜单中输入一个非我自己的配置文件时,该用户的数据显示在标题中。但当我进入时间线时,我的数据就出来了。这是我的密码 models.py(Perfil) views.py(Perfil): header.html(片段): {%if user.u经过身份验证%} {%else%} {%endif%} 这是解决方案,我与用户模型有冲突。我使用了context\u object\u name='usr',并在我的用户配置文件模板中
{%if user.u经过身份验证%}
-
{%else%}
-
-
{%endif%}
这是解决方案,我与用户模型有冲突。我使用了
context\u object\u name='usr'
,并在我的用户配置文件模板中将所有名为user的标记更改为usr
views.py
class UserProfileDetailView(generic.DetailView):
model = User
slug_field = 'username'
template_name = 'perfil/perfil.html'
context_object_name = 'usr'
def get_context_data(self, **kwargs):
context = super(UserProfileDetailView, self).get_context_data(**kwargs)
context['posts'] = Post.objects.filter(user=self.get_object())
context['follower'] = Connection.objects.filter(follower=self.get_object())
context['following'] = Connection.objects.filter(following=self.get_object())
return context
模板用户配置文件:
{{ usr.userprofile.bio }}
模板标题:
{{ user.get_full_name }}
class UserProfileDetailView(generic.DetailView):
model = User
slug_field = 'username'
template_name = 'perfil/perfil.html'
context_object_name = 'usr'
def get_context_data(self, **kwargs):
context = super(UserProfileDetailView, self).get_context_data(**kwargs)
context['posts'] = Post.objects.filter(user=self.get_object())
context['follower'] = Connection.objects.filter(follower=self.get_object())
context['following'] = Connection.objects.filter(following=self.get_object())
return context
{{ usr.userprofile.bio }}
{{ user.get_full_name }}