작정하고 Django (32) - profileapp 마무리

김의찬·2023년 5월 20일

작정하고 Django !

목록 보기
32/45

UpdateView 작성

ProfileCreateView와 거의 동일한 UpdateView

Url 등록

url path를 등록한다. 여기서 update에는 int:pk 를 명시한다.

update.html 작성

detail.html 수정

<a href="{% url 'profileapp:update' pk=target_user.profile.pk %}"> edit </a>
닉네임을 변경하고싶을 때 Update view로 라우팅을 해줄 테이블 작성

edit을 들어가면 원래의 정보가 나오게 되고 변경할 수 있는 페이지가 나오게 된다.

이미지 출력

우리가 첨부한 이미지 파일은 아직 나오지 않는다.

detail.html 에서 이미지를 올릴 수 있는 코드 작성
<img src="{{ target_user.profile.image.url}}" alt="">

하지만 이렇게 해도 이미지가 아직 나오지 않는다.

-> 해결방법

euichan - urls.py 수정

+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

MEDIA_URL 과 MEDIA_ROOT 를 연결시킴.

이미지 크기 조정 및 message 출력

  • 이미지 크기 조절

  • message 출력

  • 결과 화면

decorator 작성

기존의 decorator 를 가져와 조금 수정

views.py 에서 decorator 지정

@method_decorator(profile_ownership_required, 'post') @method_decorator(profile_ownership_required, 'get')

profile
김의찬입니다

0개의 댓글