Django при просмотре профиля другого пользователя я получаю профиль зарегистрированного пользователя
Новичок в Django и не могу понять, почему я продолжаю получать представление профиля пользователя, под которым я вошел, когда я пытаюсь просмотреть профиль другого пользователя.
HTML:
{% extends "Portfolio/base.html" %}
{% block content %}
<body>
<a href=""><i class="bi bi-pencil"></i>Send Message</a>
{% for message in message_list %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ message.sender_user.profile.image.url }}" alt="">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{% url 'profile-detail' message.sender_user.id %}">{{message.sender_user.username}}</a><small class="text-muted">  {{message.date_posted}}</small></p> {# |date:"F d, Y" #}
</div>
<p class="article-content mb-4">{{message.content|safe}}</p>
</div>
</article>
<p>{{message.seen}}</p>
{% endfor %}
Модель:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
def __str__(self):
return f'{self.user.username} Profile'
Просмотров:
''' User Profile '''
class ProfileDetailView(DetailView):
template_name = 'user/profile_detail.html' # <app>/<model>_<viewtype>.html
model = Profile
fields=('image')
def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)
URLs
path('profile/<int:pk>', user_views.ProfileDetailView.as_view(), name='profile-detail'),
Здесь в profile_detail.html мне просто нужно было использовать profile.user.username и profile.user.email вместо user.username и user.email, так что теперь все отображается правильно. Спасибо всем за помощь
<div class="media-body">
<h2 class="account-heading">{{ profile.user.username }}</h2>
<p class="text-secondary">{{ profile.user.email }}</p>
</div>
</div>