注册 登录
编程论坛 Python论坛

使用divmod()出现错误

wangjx236007 发布于 2022-02-03 13:06, 1178 次点击
运行程序 total_page_count, div = divmod(total_count, page_size),出现unsupported operand type(s) for divmod(): 'method' and 'int'  错误,请帮我一下,谢谢了。
3 回复
#2
古1232022-02-03 20:48
回复 楼主 wangjx236007
参数类型错了,找个网站翻译一下不就可以了,,,
#3
wangjx2360072022-02-04 09:11
谢谢楼主,我也知道数据类型错误,但不知道错在哪里,求帮我看一下。
class Pagination(object):
    def __init__(self,request,queryset,page_param="page",page_size=10,plus=5):
        page=request.GET.get(page_param,'1')
        if page.isdecimal():
            page=int(page)
        else:
            page=1
        self.page=page
        self.page_size=page_size
        self.start = (page - 1) * page_size
        self.end = page * page_size
        self.page_queryset=queryset[self.start:self.end]
        total_count=queryset.count
        total_page_count, div = divmod(total_count, page_size)
        if div:
            total_page_count += 1
        self.total_page_count=total_page_count
        self.plus=plus
#4
古1232022-02-04 13:46
在divmode()前面一句使用type()函数判断一下参数的类型,我这也看不出来
1