基于Django类的视图纵断面图,can';t在模板中区分已登录用户和正在修改的用户

基于Django类的视图纵断面图,can';t在模板中区分已登录用户和正在修改的用户,django,django-templates,django-users,django-generic-views,Django,Django Templates,Django Users,Django Generic Views,我正在尝试创建一个用户仪表板,我要实现的第一件事是用户配置文件。所有的配置文件都是公开的,如果用户访问他们自己的配置文件,我想添加一个编辑按钮。我的问题是,当我进入某人的页面时,它会将user变量替换为我看到的用户配置文件 我的网址: url(r'^profile/(?P<pk>\d+)$', views.ProfileView.as_view(), name='profile'), 在我的模板中: {% if user == object %}user and o

我正在尝试创建一个用户仪表板,我要实现的第一件事是用户配置文件。所有的配置文件都是公开的,如果用户访问他们自己的配置文件,我想添加一个编辑按钮。我的问题是,当我进入某人的页面时,它会将
user
变量替换为我看到的用户配置文件

我的网址:

url(r'^profile/(?P<pk>\d+)$',
    views.ProfileView.as_view(),
    name='profile'),
在我的模板中:

{% if user == object %}user and object are the same{% endif %}
{% if user == user_object %}user and object are the same{% endif %}

当当前用户在他们自己的配置文件上时,我看到
用户和对象是相同的
,但当当前用户看到另一个配置文件时,它也起作用。我错过了什么吗?为什么它们相同?

上下文处理器注入
user
变量

要解决此问题,请将字符串设置为非
“user”

class ProfileView(DetailView):
    model = get_user_model()
    context_object_name = 'user_object'
    template_name = 'accounts/profile.html'
然后在模板中使用此名称:

{% if user == object %}user and object are the same{% endif %}
{% if user == user_object %}user and object are the same{% endif %}

user
变量由上下文处理器注入

要解决此问题,请将字符串设置为非
“user”

class ProfileView(DetailView):
    model = get_user_model()
    context_object_name = 'user_object'
    template_name = 'accounts/profile.html'
然后在模板中使用此名称:

{% if user == object %}user and object are the same{% endif %}
{% if user == user_object %}user and object are the same{% endif %}

正是我需要的!感谢我所需要的!谢谢