2
클래스 기반 제네릭 뷰에 페이지 매김을 구현하려고 시도했지만 실제로는 작동하지 않습니다.클래스 기반 일반 뷰에서 페이지 매김을 사용하는 방법은 무엇입니까?
URL을
url(r'^cat/(?P<category>[\w+\s]*)/page(?P<page>[0-9]+)/$',
CategorizedPostsView.as_view(), {'paginate_by': 3}),
보기
class CategorizedPostsView(ListView):
template_name = 'categorizedposts.djhtml'
context_object_name = 'post_list'
def get_queryset(self):
cat = unquote(self.kwargs['category'])
category = get_object_or_404(ParentCategory, category=cat)
return category.postpages_set.all()
템플릿
<div class="pagination">
<span class="step-links">
{% if post_list.has_previous %}
<a href="?page={{ post_list.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ post_list.number }} of {{ post_list.paginator.num_pages }}.
</span>
{% if post_list.has_next %}
<a href="?page={{ post_list.next_page_number }}">next</a>
{% endif %}
</span>
</div>
나는 HTTP를 얻으려고 : // 127.0.0.1:8000/cat/category_name/?page = 1 또는 심지어 http : // 127.0.0.1:8000/cat/category_name/ 404 예외가 있습니다.
올바른 방법으로 클래스 기반 제네릭 뷰에서 페이지 매김을 사용하는 방법은 무엇입니까? .
감사합니다 . URL은 좀 더 간단합니다. url (r '^ cat/(? P [₩ w + \ s] *)/$, CategorizedPostsView.as_view (paginate_by = 3)),' URL의 명시 적 선언 필요가 없습니다. –
I159