Skip to content Skip to sidebar Skip to footer

Django Pagination With Dictionary Where Key Is A List

I have a dictionary in my views.py file where the values are lists. In my template I have the following html: {% for key, values in my_dict %}

Solution 1:

I am not sure if it can be count as good answer but anyway: I have just tried to replicate your problem and solution with tuple and it worked. So I think the problem can be in your code. My test code:

>>>from django.core.paginator import Paginator>>>d = {'a': [1,2], 'b': [3,4]}>>>p = Paginator(d, 1)>>>p1 = p.page(1)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: unhashable type
>>>t = tuple(d.items())>>>t
(('a', [1, 2]), ('b', [3, 4]))
>>>p = Paginator(t, 1)>>>p.page(1).object_list
(('a', [1, 2]),)
>>>p.page(2).object_list
(('b', [3, 4]),)

UPDATE: and looping also works. So can you show what structures do you have?

Post a Comment for "Django Pagination With Dictionary Where Key Is A List"