Django forms: need more than 1 value to unpack

扶醉桌前 提交于 2019-12-24 08:48:15

问题


I'm a newer to Python, and I am having a problem with Django's forms:

  args="[('job_201404181748_1712666','job_201404181748_1712666')]"
  jobid = forms.ChoiceField(choices=args)

This raised ValueError: need more than 1 value to unpack. If I replace args with a string, then it works ok:

 jobid = forms.ChoiceField(choices=[('job_201404181748_1712666','job_201404181748_1712666')])

I don't know why. Can anyone help?


回答1:


Try args without the surrounding quotes. By surrounding it with quotes, you make args into a string. The ChoiceField expect a list of choices.

in short, make line 33 look like:

 args=[('job_201404181748_1712666','job_201404181748_1712666')]



回答2:


You need to remove the quotes

args=[('job_201404181748_1712666','job_201404181748_1712666')]


来源:https://stackoverflow.com/questions/23152700/django-forms-need-more-than-1-value-to-unpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!