매김 코드 :queryset이 비어 있는지 확인하는 방법?
try:
page = paginator.page(page_number)
print(page.object_list)
그래서 다음과 같은 출력이 내 페이지 매김을위한 print(page.object_list)
의 결과입니다
<QuerySet [<Comment: I can't believe it's happeinig>, <Comment: Just trying to fill up the comments>, <Comment: Another one!>, <Comment: Evenmore noe>, <Comment: Something>, <Comment: Lol>, <Comment: Are comments showing up?>, <Comment: Great for the economy.>, <Comment: honestly>, <Comment: Even though the the onlyEven though the only one to udnertstnaf!>]>
<QuerySet [<Comment: Yeah it's crazy how fast aswell. It's very awesome how it's doing atm. >]>
<QuerySet []>
<QuerySet [<Comment: Sure>, <Comment: No worries>]>
<QuerySet []>
<QuerySet []>
<QuerySet [<Comment: attempt 2!>]>
<QuerySet [<Comment: Attempt 3!>]>
<QuerySet []>
<QuerySet [<Comment: 12>]>
<QuerySet []>
<QuerySet [<Comment: Somewhere?>]>
<QuerySet []>
<QuerySet [<Comment: lol>]>
<QuerySet []>
<QuerySet [<Comment: 12>]>
<QuerySet []>
당신은 내가 빈 검색어 세트를 가지고 있고,이 내 코드에서 오류를 일으키는 볼 수 있듯이. 따라서 나는 이러한 쿼리 세트를 반복하고 빈 샘플을 찾아 내고 싶습니다. 나는 루프에 대해이 작업을 추가하려고 :
for i in page.object_list:
if len(i) < 0:
하지만 오류 얻을 : 어떤 도움을 주시면 감사
TypeError at /news/11/
object of type 'Comment' has no len()
합니다.
은 비어있는 경우는 A의 검색어를 삭제하려고 :
try:
page = paginator.page(page_number)
if page.object_list:
pass
else:
page.delete()
오류 :
AttributeError at /news/11/
'CustomPage' object has no attribute 'delete'
페이지 매거진을 만들기 전에 쿼리 세트를 필터링해야합니다. – Sayse