작정하고 장고 33강- get_success_url 함수 그리고 리팩토링

짜부·2023년 2월 6일

작정하고 장고

목록 보기
40/41

Profile view에서 success_url수정

detail 페이지로 이동시키고 싶어서

이렇게 하면 작동안됨. 왜냐하면 detail페이지는 pk를 받아SS야 하기 때문이다. 따로 넘겨줄수없기 때문에 내부 메소드를 수정시켜주어야함.

  • ProfileCreateView, ProfileUpdateView에 success_url삭제후 추가

login안해도 edit버튼이 나오는것 수정

profile이 있을 때 추가적인 인증과정 없이 수정링크로 들어갈수 있는 edit을 보여주기 때문이다.
if문을 이용하여 인증과정을 넣어준다.

그밖의 닉네임 미설정을 보여주는 등 자잘한 설정을 해줌

<div>
        <div style="text-align: center; max-width: 500px; margin: 4rem auto;">
            {% if target_user.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'">
                {{ target_user.profile.nickname }}
                {% if 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 %}
                {% if target_user == user %}
                    <a href="{% url 'profileapp:create' %}">
                        <h2 style="font-family: 'NanumSquareB'">
                            Create Profile
                        </h2>
                    </a>

                {% else %}
                <h2>
                    닉네임 미설정
                </h2>
                {% endif %}
            {% endif %}

배운것 정리

  • success_url 수정(pk가 있을때 get_success_url함수 재정의)
  • 로그아웃해도 profile edit이 나오는 에러 수정. (자신의 프로필인증 추가)
profile
화이팅

0개의 댓글