I would like to ask my django paging component, back end to end of the data transfer, if it is in the form of a list set of dictionaries can be normal paging, I send a two-dimensional array form, paging component failure, please help me to see what the pr

gxj678 注册会员
2023-02-27 16:33

Hopefully, the Django paging component needs to receive an iterable object, so the incoming data must be an iterable object, such as a list, dictionary, etc. If you pass in a two-dimensional array, you may cause the paging component to fail.

xiong_sir 注册会员
2023-02-27 16:33

This answer quotes chatgpt, see if it works


may be in the init function of the paging component, because in this function, it uses the queryset[self.start:self.end] to get the paging data, where the queryset should be a list, When you pass in a two-dimensional array, it may not be properly converted to a list dictionary, causing the paging component to process the data incorrectly.

To solve this problem, you can convert a two-dimensional array into a list dictionary before passing in the data. For example, you could do this in a view function:

def www(request):
    file_object = request.FILES.get("file")
    if file_object:
        data = xlrd.open_workbook(filename=None, file_contents=file_object.read())
        sheet = data.sheet_by_index(0)
        nrows = sheet.nrows
        list = []
        for i in range(1, nrows):
            list.append(dict(zip(range(sheet.ncols), sheet.row_values(i))))
        queryset = np.array(list)
        p = pre()
        queryset = p.wave(queryset)
        queryset = np.round(queryset,6)
        page_object = Pagination(request, queryset)
        context = {"queryset": page_object.page_queryset,
                   "page_string": page_object.html()
        return render(request, 'wave2.html', context)
    return render(request,'wave.html')

Here we use dict(zip(range(sheet.ncols), sheet.row_values(i))) to convert a row of data to a dictionary and add all the dictionaries to the list, thus converting a two-dimensional array to the form of a list-set dictionary

dahai32623313 注册会员
2023-02-27 16:33
< div class = "md_content_show e397 data - v - 3967" = "" >

thanks for brother answer! But now the problem is that p=pre() is an object I instantiated, and this module requires that the data passed in must be an array. The function of this page is to display the preprocessed data of this module to the web page, so you see if there is a way to display the preprocessed data of this module after queryset = np.round(queryset,6), Convert a two-dimensional array into a list dictionary.

About the Author

Question Info

Publish Time
2023-02-27 16:33
Update Time
2023-02-27 16:33

Related Question