Permalink
Browse files

query_paginationに合わせたURL指定実装

  • Loading branch information...
高山雄貴 高山雄貴
高山雄貴 authored and 高山雄貴 committed Sep 24, 2018
1 parent fb918ac commit 613c59ca0624865e231bbb781f258af77cb0b73f
View
BIN +0 Bytes (100%) db.sqlite3
Binary file not shown.
View
Binary file not shown.
@@ -53,18 +53,18 @@ <h3 class="card-header">{{ village.name }}</h3>
<nav>
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="{% url 'index' %}?page={{ page_obj.previous_page_number }}">前へ</a></li>
<li class="page-item"><a class="page-link" href="{% url 'index' %}?{% query_pagination request page_obj.previous_page_number %}">前へ</a></li>
{% endif %}
{% for link_page in page_obj.paginator.page_range %}
{% if link_page == page_obj.number %}
<li class="page-item active"><span class="page-link" href="#">{{ link_page }}</span></li>
{% else %}
<li class="page-item"><a class="page-link" href="{% url 'index' %}?page={{ link_page }}">{{ link_page }}</a></li>
<li class="page-item"><a class="page-link" href="{% url 'index' %}?{% query_pagination request link_page %}">{{ link_page }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="{% url 'index' %}?page={{ page_obj.next_page_number }}">次へ</a></li>
<li class="page-item"><a class="page-link" href="{% url 'index' %}?{% query_pagination request page_obj.next_page_number %}">次へ</a></li>
{% endif %}
</ul>
</nav>
Binary file not shown.
@@ -4,7 +4,10 @@
@register.simple_tag
def query_pagination(request, page_number):
#request.GETの値コピー
querydict = request.GET.copy()
querydict['page']=page_number
#ページ情報を代入 # Django2.1対策。通常はvalueだけでOK
querydict['page'] = str(page_number)
#ページに関するクエリ生成
#htto://~?以下の検索クエリを返す
return querydict.urlencode()
View
@@ -1,7 +1,6 @@
from django.shortcuts import render,get_object_or_404
from .models import Village,Character
from django.views import generic
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# Create your views here.
#初期検索・一覧画面

0 comments on commit 613c59c

Please sign in to comment.