在我的应用程序中,我需要用户从下拉列表中选择一个整数值。我想我会为此创建一个表单,如下所示
class CIForm(forms.Form):
intervaloption = forms.ChoiceField(choices = [x for x in range(1,10)],label='Days taken')
但是,当我尝试在 django shell 中使用 as_p() 显示它时,它抛出了一个 TypeError
In [29]: f= CIForm()
In [30]: f
Out[30]: <__main__.CIForm object at 0xaa93eec>
In [31]: print f.as_p()
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (41, 0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
...
TypeError: 'int' object is not iterable
我无法弄清楚我做错了什么..你能帮忙吗?