DetailView를 활용한 개인 페이지 구현
class AccountDetailView(DetailView):
model = User
context_object_name = 'target_user'
template_name = 'accountapp/detail.html'
Detail View를 만들어준다.(read)
path('detail/<int:pk>', AccountDetailView.as_view(), name='detail')
accountapp의 urls.py에 해당 path를 추가해준다 여기서 pk는 기본키를 의미한다.
{% extends 'base.html' %}
{% block content %}
<div style="text-align: center; max-width: 500px; margin: 4rem auto">
<div>
<p>
{{ target_user.date_joined }}
</p>
<h2 style="font-family:'NanumGothic'">
{{ target_user.username }}
</h2>
</div>
</div>
{% endblock %}
detail.html을 만들어준다.
<a href="{% url 'accountapp:detail' pk=user.pk %}">
<span>Mypage</span>
</a>
header.html에 Mypage를 볼 수 있도록 추가해준다.
로그인후 상단의 Mypage를 눌러주면
다음과 같이 가입 날짜와 아이디가 출력된다.
'기타 > django' 카테고리의 다른 글
작정하고 장고 - Authentication 인증시스템 구축 (0) | 2023.05.15 |
---|---|
작정하고 장고 - UpdateView, DeleteView (0) | 2023.05.13 |
작정하고 장고 - Bootstrap을 이용한 Form 디자인 정리 (0) | 2023.05.10 |
작정하고 장고 - login, logout 구현 (0) | 2023.05.09 |
작정하고 장고 - CreateView를 통한 회원가입 구현 (0) | 2023.05.08 |
댓글