success_url
success_url = reverse_lazy('accountapp:detail') 로 수정pk 라는 추가적인 데이터가 가야하는데success_url = reverse_lazy('accountapp:detail')

kwargs={'pk':self.object.user.pk} 와 같이 넘겨준다.model = Profile 인데
kwargs={'pk':self.object.user.pk} 로 넘겨주는 것.# profileapp/views.py
class ProfileCreateView(CreateView):
model = Profile
context_object_name = 'target_profile'
form_class = ProfileCreationForm
template_name = 'profileapp/create.html'
def form_valid(self, form):
temp_profile = form.save(commit=False)
temp_profile.user = self.request.user
temp_profile.save()
return super().form_valid(form)
# 추가
def get_success_url(self):
return reverse('accountapp:detail', kwargs={'pk': self.object.user.pk})
@method_decorator(profile_ownership_required, 'get')
@method_decorator(profile_ownership_required, 'post')
class ProfileUpdateView(UpdateView):
model = Profile
context_object_name = 'target_profile'
form_class = ProfileCreationForm
success_url = reverse_lazy('accountapp:hello_world')
template_name = 'profileapp/update.html'
# 추가
def get_success_url(self):
return reverse('accountapp:detail', kwargs={'pk': self.object.user.pk})


accountapp/templates/accountapp/detail.html 수정 필요nickname을 보여주는 동시에 추가적인 인증 과정 없이 이 edit 으로 향하고Create Profile 을 보여주어 프로필 수정 페이지를 향하는 링크를 보여주는 문제target_user == user 이면 정상적으로 각가edit과 Create Profile 링크가 보여지도록 수정



{% extends 'base.html'%}
{% block content %}
<div>
<div style="text-align: center; max-width: 500px; margin: 4rem auto;">
<p>
{{ target_user.date_joined }}
</p>
{% if target_user.profile %} <!--(1) profile 있고 -->
<!--프로필 이미지를 보여주기-->
<img src="{{ target_user.profile.image.url }}" alt=""
style="height: 12rem; width: 12rem; border-radius: 20rem; margin-bottom: 2rem;">
<h2 style="font-family: 'NanumSquareB'">
<!--nickname 보여주기-->
{{ target_user.profile.nickname }}
<!-- 추가된 부분 -->
{% if target_user == user %} <!--(1-1) target_user == user 라면-->
<!--프로필 수정 페이지로 이동할 수 있도록-->
<a href="{% url 'profileapp:update' pk=target_user.profile.pk %}">
edit
</a>
{% endif %}
<!--------------->
</h2>
<!--대화명을 보여주기-->
<h5 style="margin-bottom: 3rem;">
{{ target_user.profile.message }}
</h5>
{% else %} <!--(2) profile 이 없는데-->
<!-- 추가된 부분 -->
{% if target_user == user %} <!-- (2-1) target_user == user 이라면-->
<!--프로필 생성 페이지로 이동할 수 있도록-->
<a href="{% url 'profileapp:create' %}">
<h2 style="font-family: 'NanumSquareB'">
Create Profile
</h2>
</a>
<!-- (2-2) 단순히 프로필만 없다면-->
{% else %}
<h2>
닉네임 미설정 <!--다음 출력-->
</h2>
{% endif %}
<!--------------->
{% endif %}
{% if target_user == user %}
<a href="{% url 'accountapp:update' pk=user.pk%}">
<p>
Change Info
</p>
</a>
<a href="{% url 'accountapp:delete' pk=user.pk%}">
<p>
Quit
</p>
</a>
{% endif %}
</div>
</div>
{% endblock %}
