Django template : Need 2 values to unpack in for loop; got 8

Djamel

Through my view I collected some data that I want to bundle together in a list of values that look like this :

data = [(1,2,3,4,5,6,7,8),(1,2,3,4,5,6,7,8),(1,2,3,4,5,6,7,8)]

Then I'll be rendering that to my template to unpack the data to my page :

return render(request, 'accounts/page.html', {'data' : data})

Template goes like this :

{% for a,b,c,d,e,f,g,h in data %}
    <h3>{{a}}</h3>
    <h3>{{b}}</h3>
    #and so on
    #..
    <h3>{{h}}</h3>
{% endfor %}

So the error i get is :

Need 2 values to unpack in for loop; got 8.

Can anyone figure out the source of this error or maybe have a better way of rendering data in bundles ?

Thanks !

Wariored

Be careful to not use list as variable it is depreciated since it is a Python Type Object(reserved)
And the problem is only in your render:

my_list = [(1,2,3,4,5,6,7,8),(1,2,3,4,5,6,7,8),(1,2,3,4,5,6,7,8)]
return render(request, 'accounts/page.html', {'my_list': my_list})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django ValueError: Need 3 values to unpack in for loop; got 2. How to unpack zipped data in template?

ValueError not enough values to unpack (expected 4, got 2) - Django

Django ValueError - not enough values to unpack (expected 2, got 1)

for loop - Not enough values to unpack (expected 3, got 2) but I am providing it with 3

Django Multiple Record Insert CreateView ( not enough values to unpack (expected 2, got 1))

nm, address = addr ValueError: not enough values to unpack (expected 2, got 1), Django Rest Framework

ValueError: not enough values to unpack (expected 8, got 1)

ValueError: need more than 2 values to unpack

Python ValueError: not enough values to unpack (expected 3, got 2)

Python 3 - ValueError: not enough values to unpack (expected 3, got 2)

python3: not enough values to unpack (expected 2, got 0)

How to fix "ValueError: not enough values to unpack (expected 2, got 1)"

How to fix 'not enough values to unpack (expected 2, got 1)' error

ValueError: not enough values to unpack (expected 3, got 2) in Pytorch

ValueError in python OpenCV - not enough values to unpack (expected 3, got 2)

ValueError: not enough values to unpack (expected 3, got 2) (OpenCV)

Networkx - ValueError: not enough values to unpack (expected 3, got 2)

ValueError: not enough values to unpack (expected 2, got 1) Wrong

ValueError: not enough values to unpack (expected 2, got 1) when trying to unpack dict in python for data labeling with pandas

ValueError: need more than 2 values to unpack - When reading GRAYSCALE

"ValueError: need more than 2 values to unpack" while using enumerate()

PYTHON: need more than 0 values to unpack (compare 2 files)

ValueError: not enough values to unpack (expected 2, got 1) BUT i provide 2 values

Not enough values to unpack from dictionary items: expected 3 values, got 2

Error: Too many values unpack (expected 2) when trying to loop

How can I fix this "ValueError: not enough values to unpack (expected 3, got 2)"?

Getting this error "ValueError: not enough values to unpack (expected 3, got 2)" while compiling opencv contours

on Google Colab with pyhton: ValueError: not enough values to unpack (expected 3, got 2)

Marshmallow for python giving ValueError: not enough values to unpack (expected 2, got 1)