Django表单:需要多于1个值才能解压缩 [英] Django forms: need more than 1 value to unpack
本文介绍了Django表单:需要多于1个值才能解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Python的新手,而Django表单有问题:
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)
这引发了 ValueError:需要多于1个值来解压缩
。如果我用字符串替换 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?
推荐答案
尝试 args
通过用引号括起来,您可以将 args
转换为字符串。 ChoiceField希望有一个选择列表。
Try args
without the surrounding quotes. By surrounding it with quotes, you make args
into a string. The ChoiceField expect a list of choices.
简而言之,让第33行看起来像:
in short, make line 33 look like:
args=[('job_201404181748_1712666','job_201404181748_1712666')]
这篇关于Django表单:需要多于1个值才能解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文