Q&A
책을 따라하다가 막히는 부분이 있나요?
질문을 남겨주세요.
이 페이지는 의견 교환을 위해 따로 만든 페이지입니다. 책에서 이 페이지를 만드는 법을 직접적으로 다루지는 않습니다.
하지만, 책을 끝까지 읽고 나면 이 페이지도 만드실 수 있을거에요.
하지만, 책을 끝까지 읽고 나면 이 페이지도 만드실 수 있을거에요.
p473 코드와 저한테 있는 코드가 너무 달라서 계속 오류가 나와요
2 years, 12 months ago
xlqnxl<div id="comment-area">
<!-- Comments section-->
<section class="mb-5">
<div class="card bg-light">
<div class="card-body">
<!-- Comment form-->
<form class="mb-4"><textarea class="form-control" rows="3" placeholder="Join the discussion and leave a comment!"></textarea></form>
<!-- Comment with nested comments-->
<div class="d-flex mb-4">
<!-- Parent comment-->
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">Commenter Name</div>
If you're going to lead a space frontier, it has to be government; it'll never be private enterprise. Because the space frontier is dangerous, and it's expensive, and it has unquantified risks.
<!-- Child comment 1-->
<div class="d-flex mt-4">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">Commenter Name</div>
And under those conditions, you cannot establish a capital-market evaluation of that enterprise. You can't get investors.
</div>
</div>
<!-- Child comment 2-->
<div class="d-flex mt-4">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">Commenter Name</div>
When you put money directly to a problem, it makes a good headline.
</div>
</div>
</div>
</div>
{% if post.comment_set.exists %}
{% for comment in post.comment_set.iterator %}
<!-- Single comment-->
<div class="d-flex" id="comment-{{ comment.pk }}">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">{{ comment.author.username }} <small class="text-muted">{{ comment.created_at }}</small></div>
<p>{{ comment.content | linebreaks }}</p>
</div>
</div>
{% endfor %}
{% endif %}
</div>
<hr/>
</div>
</section>
</div>
이거는 제가 갖고 있는 코드고 어느 정도 수정이 필요할 거 같아서 아래와 같이 수정해서
<div id="comment-area">
<!-- Comments section-->
<section class="mb-5">
<div class="card bg-light">
<div class="card-body">
<!-- Comment form-->
{% if user.is_authenticated %}
<form id="comment-form" method="POST" action="{{ post.get_absolute_url }} new_comment/">
<textarea class="form-control" rows="3" placeholder="Join the discussion and leave a comment!"></textarea></form>
</form>
{% else %}
<a role="button" class="btn btn-outline-dark btn-block btn-sm" href="#" data-toggle="modal" data-target="#loginModal">Log in and leave a comment</a>
{% endif %}
{% if post.comment_set.exists %}
{% for comment in post.comment_set.iterator %}
<!-- Single comment-->
<div class="d-flex" id="comment-{{ comment.pk }}">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">{{ comment.author.username }} <small class="text-muted">{{ comment.created_at }}</small></div>
<p>{{ comment.content | linebreaks }}</p>
</div>
</div>
{% endfor %}
{% endif %}
</div>
<hr/>
</div>
</section>
</div>
테스트를 돌려보면
Traceback (most recent call last):
File "D:\GitHub\doitdjangoatoz\blog\tests.py", line 301, in test_comment_form
self.assertEqual('Log in and leave a comment', comment_area.text)
AssertionError: 'Log in and leave a comment' != '\n\n\n\n\n\nLog in and leave a comment\n\[61 chars]\n\n'
- Log in and leave a comment
+
Log in and leave a comment
king Nov. 25, 2021, 4:13 a.m.
첫번째댓글
----------------------------------------------------------------------
Ran 7 tests in 3.062s
FAILED (failures=1)
Destroying test database for alias 'default'...
이렇게 나오는데 뭐가 문젠지 모르겠어요
목록보기
benn 2 years, 12 months ago
조심스럽게 답변을 달아봅니다!
에러 코드를 보면
'Log in and leave a comment' != '\n\n\n\n\n\nLog in and leave a comment\n\[61 chars]\n\n'
!= 로 나오는데, 테스트 코드에서 self.assertEqual로 작성하신 것으로 추측됩니다.
서적을 보면 self.assertIn 로 나와있습니다.
코드를 self.assertIn('Log in and leave ....')으로 수정하시면 제대로 작동할 것 같습니다. :)
Updated: Nov. 26, 2021, 11:51 a.m.
xlqnxl 2 years, 12 months ago
오 그 부분은 넘어갔습니다
답변 감사합니다!
Updated: Nov. 27, 2021, 9:47 p.m.
sungyong 2 years, 11 months ago
와 감사합니다!
Updated: Nov. 28, 2021, 12:08 p.m.
Leave a Comment: