페이지 기능이 작동하지 않습니다.

점프 투 장고, 파이보 연습중인데요.

페이지 기능이 잘 되었었는데.
검색 기능 추가하면서
자바 스크립트를 추가 하니까.
검색은 잘 되는데.
페이지 번호를 누르면 작동을 하지 않네요.

아래와 같이페이지 번호가 아예 넘어가 지지를 않아요.
[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 %}

{% if question_list %} {% for question in question_list %} {% endfor %} {% else %} {% endif %}
번호 글쓴이 제목 작성일시
{{ 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 224

2023년 8월 18일 3:01 오후

작성하신 소스와 다음 URL의 코드에 차이가 없는지 확인해 보세요. https://github.com/pahkey/jump2django/tree/3-14 - 박응용님, 2023년 8월 18일 3:23 오후 추천 , 대댓글
@박응용님 a href="#" 을 javascript:void(0) 로 바꾸고. 아래쪽의 스크립트도 동일하게 바꿨는데도 페이지 번호 undefined 가 뜨고 안되어서. 깃허브의 소스를 그대로 가져다 놓으니 검색, 페이지 모두 정상 작동합니다. 제 소스에서 무언가 틀린 곳이 있는거 같은데. 찾을 수가 없네요. 아뭏든 고맙습니다. - irchama님, 2023년 8월 18일 3:47 오후 추천 , 대댓글
목록으로