TypeError 질문입니다.
조회수 908회
현재 만들고 있는 기능은 오늘 생일인 사람을 보여주는 기능 입니다. 그래서 account앱의 모델의 UserProfile에서 birthday를 만들어 notice앱의 뷰를 통해서 텝플릿에 정보를 전달할 예정입니다. 문제는 회원의 생일을 담고 있는 birthday_list의 원소를 하나씩 오늘 날짜와 비교하여 오늘 생일인 사람을 리스트에 넣어 템플릿에 전달하려 했는데 TypeError가 발생하였고 'expected string or bytes-like object'이런 메시지가 발생합니다. 제가 어떤 잘못을했는지 알려주시면 감사하겠습니다!
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
email = models.EmailField(null=True)
full_name = models.CharField(max_length=50)
birthday = models.DateField()
def __str__(self):
return self.user.username
account앱의 model입니다.
def index(request):
fre_question_list = FrequentQuestion.objects.all()
notice_list = Notice.objects.all()
birthday_list = UserProfile.objects.all() #accounts앱에서 db가져오기
today = date.today() #오늘날짜
today_month_day = today.strftime("%m-%d") #오늘날짜 MM-dd 형식으로 가져오기
today_birth_list = [] #오늘 생일 일자인 사람들을 담을 리스트
for birth_month_day in birthday_list:
regex = re.compile(r'(\d{2}-\d{2})$') #오늘 생일인 사람들의 생일을 오늘날짜 MM-dd 형식으로 바꾸기
match_obj = regex.search(birth_month_day.birthday)
birthday = match_obj.group()
if birthday == today_month_day:
today_birth_list.append(birth_month_day) #리스트에 집어넣기
if today_birth_list:
return render(request, 'notice_board/index_notice.html', {'today_birth_list': today_birth_list,
'fre_question_list': fre_question_list,
'notice_list': notice_list
})
return render(request, 'notice_board/index_notice.html', {'fre_question_list': fre_question_list,
'notice_list': notice_list})
제가 생일 정보를 템플릿에 넘기려는 notice앱의 view의 함수 중 하나입니다.
<div class="birthday_box">
{% if today_birth_list %}
<ul class="new_ul" style="padding: 10px 0; border-bottom: 1px black">
{% for birth_person in today_birth_list %}
<li class="new_list" style="padding: 10px;">
{{ birth_person.birthday }}
</li>
{% endfor %}
</ul>
{% else %}
<p>오늘자 생일인 동아리 회원이 없습니다.</p>
{% endif %}
</div>
정보를 넘기려는 템플릿입니다.
댓글 입력