
# pragmatic/accountapp/views.py
from django.views.generic import CreateView, DetailView
...
class AccountDetailView(DetailView):
model = User
template_name = 'accountapp/detail.html'
<!--pragmatic/accountapp/templates/accountapp/deatil.html-->
{% extends 'base.html'%}
{% block content %}
<div>
<div style="text-align: center; max-width: 500px; margin: 4rem auto;">
<p>
{{ user.date_joined }} <!--언제 가입을 했는지-->
</p>
<h2>
{{ user.username }}
</h2>
</div>
</div>
{% endblock%}
...
from accountapp.views import hello_world, AccountCreateView, AccountDetailView
...
urlpatterns = [
...
path('create/', AccountCreateView.as_view(), name='create'),
path('detail/<int:pk>', AccountDetailView.as_view(), name='detail'),
]
<a href="{% url 'accountapp:detail' pk=user.pk %}" ><div class="pragmatic_header">
<div>
<h1 class="pragmatic_logo">Prgmatic</h1>
</div>
<div>
...
{% if not user.is_authenticated %}
<a href="{% url 'accountapp:login' %}?next={{ request.path }}">
<span>login</span>
</a>
{% else %}
<a href="{% url 'accountapp:detail' pk=user.pk %}" >
<span>MyPage</span>
</a>
<a href="{% url 'accountapp:logout' %}?next={{ request.path }}">
<span>logout</span>
</a>
{% endif %}
</div>
</div>



{{ user.date_joined }}
Detail 의 User 를 instagram 느낌으로 생각해보면 로그인이 되어있는지 확인을 하고 본인 user 의 정보를 보여주게 되는데, 특정 pk 를 가진 user 의 정보를 보여주어야 한다.
이런식으로 하면은 접속한 유저, 예를 들면 내가 다른 연예인 페이지를 들어가더라도 나의 정보를 보여주도록 해주어야함.
context_object_name
{{ user.date_joined }}) 이 user 객체의 이름을 다르게 설정해주어야 한다.target_user 로 설정하면, 다른 사람이 우리의 페이지에 오더라도 우리의 페이지를 볼 수 있게 각 사용자(객체)의 객체 이름을 따로 지정# pragmatic/accountapp/views.py
class AccountDetailView(DetailView):
model = User
context_object_name = 'target_user' # 추가
template_name = 'accountapp/detail.html'
<!--pragmatic/accountapp/templates/accountapp/detail.html-->
{% extends 'base.html'%}
{% block content %}
<div>
<div style="text-align: center; max-width: 500px; margin: 4rem auto;">
<p>
{{ target_user.date_joined }} <!-- 수정 -->
</p>
<h2 style="font-family: 'NanumSquareB'"> <!-- 볼드체 폰트로 수정-->
{{ target_user.username }} <!-- 수정 -->
</h2>
</div>
</div>
{% endblock %}
