어제 생겼던 오류를 해결할 방법은 어렵지 않았다.
새로 만든 함수를 사용을 해주는 것이 아닌 기존에 사용하던 함수를 이용해주는 방법이었다.
user_id = request.session.get('user_id')
try:
user_profile = UserProfile.objects.get(user_id=user_id)
except UserProfile.DoesNotExist:
user_profile = None # 프로필이 없으면 None으로 설정
context = {
......
'user_profile':user_profile,
}
그 후 post_detail에서 user_profile값을 comment_template로 보내주는 방법을 찾아봤더니 아주 단순한 방법이 있었다.
{% include 'book/comment_template.html' with comment=comment user_profile=user_profile %}
위와 같이 값을 보내고
<form method="post" action="{% url 'comment_profile_image' post.pk %}" enctype="multipart/form-data">
<img
src="{% if user_profile.profile_image %} http://127.0.0.1:8000/book{{ user_profile.profile_image }}{% endif %}"
alt="Profile Picture"
style="cursor: pointer; width: 50px; height: 50px; border-radius: 50%;"
>
</form>
바로 comment_template에서 값을 받아 출력하니 이미지가 잘 출력이 되었다. 이제 사이즈하고 위치를 수정을 해줘야 한다.
'장고' 카테고리의 다른 글
개발 일지 32 - 댓글 프로필 이미지 마무리 (0) | 2024.09.15 |
---|---|
개발 일지 31 - 댓글 프로필 이미지 추가..3 (0) | 2024.09.14 |
개발 일지 29 - 댓글 프로필 이미지 추가 (2) | 2024.09.12 |
개발 일지 28 - 프로필 이미지 오류..3 (0) | 2024.09.11 |
개발 일지 27 - 프로필 이미지 추가 2 (0) | 2024.09.10 |