페이지 기능이 작동하지 않습니다.
점프 투 장고, 파이보 연습중인데요.
페이지 기능이 잘 되었었는데.
검색 기능 추가하면서
자바 스크립트를 추가 하니까.
검색은 잘 되는데.
페이지 번호를 누르면 작동을 하지 않네요.
아래와 같이페이지 번호가 아예 넘어가 지지를 않아요.
[18/Aug/2023 14:49:01] "GET /?kw=&page= HTTP/1.1" 200 8597
수동으로 페이지 번호를 넣어서 넘기면 잘 나옵니다.
아래는 question_list.html 과 base_views.py 파일 내용입니다.
question_list.html
{% extends 'base.html' %}
{% load pybo_filter %}
{% block content %}
번호 | 글쓴이 | 제목 | 작성일시 |
---|---|---|---|
{{ question_list.paginator.count|sub:question_list.start_index|sub:forloop.counter0|add:1 }} | {{ question.author.username }} | {{ question.subject }} {% if question.answer_set.count > 0 %} {{ question.answer_set.count }} {% endif %} | {{ question.create_date }} |
질문이 없습니다. |
-
{% if question_list.has_previous %}
- 이전 {% else %}
- 이전 {% endif %} {% for page_number in question_list.paginator.page_range %} {% if page_number >= question_list.number|add:-5 and page_number <= question_list.number|add:5 %} {% if page_number == question_list.number %}
- {{ page_number }} {% else %}
- {{ page_number }} {% endif %} {% endif %} {% endfor %} {% if question_list.has_next %}
- 다음 {% else %}
- 다음 {% endif %}
{% endblock %}
{% block script %}
{% endblock %}
base_views.py
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator
from django.db.models import Q
from ..models import Question
def index(request):
# 입력인자
page = request.GET.get('page','1')
kw = request.GET.get('kw', '')
question_list = Question.objects.order_by('-create_date')
if kw:
question_list = question_list.filter(
Q(subject__icontains=kw) |
Q(content__icontains=kw) |
Q(author__username__icontains=kw) |
Q(answer__author__username__icontains=kw)
).distinct()
# paging 처리
paginator = Paginator(question_list, 10)
page_obj = paginator.get_page(page)
context = {'question_list': page_obj, 'page': page, 'kw': kw}
return render(request, 'pybo/question_list.html', context)
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
context = {'question' : question}
return render(request, 'pybo/question_detail.html', context)
irchama 님 275
2023년 8월 18일 3:01 오후
