Django: ValueError: too many values to unpack
I came across this error this morning on a Django project that I’m working on in my spare time. I was trying to add some custom permissions to one of the models, as outlined in the documentation, only to have it choke with this message when I ran manage.py syncdb
.
A bit of Googling got me to this site, but unfortunately it’s in Polish. Never mind, Google Translate managed to give me enough information. Turns out that I had missed out a comma that I didn’t think was necessary:
class Meta:
permissions = (
("can_drive", "Can drive"),
("can_vote", "Can vote in elections"),
("can_drink", "Can drink alcohol"), # <== This comma is important!
)
Hmmm, I always thought that last comma in Python was only an optional extra in case you decided to add an extra item to the end of a tuple and forgot to add it in to the previous line. Seems it does have some obscure but significant semantic importance after all.
Thanks for posting this. It saved me a lot of time. Cheers!
I just wanted to add that I got this error because I was missing the comma on my PAGE_TEMPLATES tuple. FYI.
create lists with defined number of elements
list = [] * 100
enjoy