where is the error in pagination?

35 views
Skip to first unread message

leb dev

unread,
Sep 25, 2019, 7:01:27 AM9/25/19
to Django users
i have a django project  and it includes pagination i do not know where is the error in my code but once i tired to go to the next or previous page it crash and display the below error :

> can only concatenate str(not ""NoneType) to str

            query=request.GET.get("search")
            paginator = Paginator(queryset_list, 5) 
            page_request_var = "page"
            print("page_request_var===>",page_request_var)
            page = request.GET.get(page_request_var)
            print("page===>",page)
            queryset = paginator.get_page(page)
            print("queryset===>",queryset)

When i print **page** it display None


 In the browser it suppose to display **page=2&search=sam**
but instead 
it display **/?=2&20search%20=%20sam**

laya

unread,
Sep 25, 2019, 7:04:37 AM9/25/19
to django...@googlegroups.com

Hi,

Do you use Class Based View ?

 

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/82e3fe0e-e872-4a49-b869-2b67001e3270%40googlegroups.com.

 

leb dev

unread,
Sep 25, 2019, 7:10:19 AM9/25/19
to Django users
no i am using function based views

laya

unread,
Sep 25, 2019, 7:15:41 AM9/25/19
to django...@googlegroups.com

Try this one :

paginator = Paginator(queryset_list,8# Show 25 contacts per page
page_request_var = "page"
page = request.GET.get(page_request_var)
try:
    queryset = paginator.page(page)
except PageNotAnInteger:
   
# If page is not an integer, deliver first page.
   
queryset = paginator.page(1)
except EmptyPage:
   
# If page is out of range (e.g. 9999), deliver last page of results.
   
queryset = paginator.page(paginator.num_pages)

 

 

Sent from Mail for Windows 10

 

From: leb dev
Sent: Wednesday, September 25, 2019 2:32 PM
To: Django users

--

leb dev

unread,
Sep 25, 2019, 7:33:24 AM9/25/19
to Django users
i tried your answer and display an error :

That page number is not an integer

laya Mahmoudi

unread,
Sep 25, 2019, 7:39:16 AM9/25/19
to django...@googlegroups.com
Would you send your html codes relating to pagination

در تاریخ چهارشنبه ۲۵ سپتامبر ۲۰۱۹،‏ ۱۵:۰۳ leb dev <testd...@gmail.com> نوشت:
i tried your answer and display an error :

That page number is not an integer

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

leb dev

unread,
Sep 25, 2019, 7:43:29 AM9/25/19
to Django users
<div class="pagination">
    <span class="step-links">
        {% if object_list.has_previous %}
            <a href="?{{page_request_var}}=1">&laquo; first</a>
            <a href="?{{page_request_var }}={{ object_list.previous_page_number }}{% if request.GET.q%}&q={{request.GET.q }}{% endif %}">previous</a>
        {% endif %}

        <span class="current">
            Page {{ object_list.number }} of {{ object_list.paginator.num_pages }}.
        </span>

        {% if object_list.has_next %}
            <a href="?{{page_request_var}}={{ object_list.next_page_number }}{% if request.GET.q%}&q={{request.GET.q }}{% endif %}">next</a>
            <a href="?{{page_request_var}}={{ object_list.paginator.num_pages }}">last &raquo;</a>
        {% endif %}
    </span>
</div>

On Wednesday, September 25, 2019 at 2:39:16 PM UTC+3, laya Mahmoudi wrote:
Would you send your html codes relating to pagination

در تاریخ چهارشنبه ۲۵ سپتامبر ۲۰۱۹،‏ ۱۵:۰۳ leb dev <testd...@gmail.com> نوشت:
i tried your answer and display an error :

That page number is not an integer

-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages