Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在Django上填写自定义choicefield表单_Python_Django_Forms_Choicefield - Fatal编程技术网

Python 无法在Django上填写自定义choicefield表单

Python 无法在Django上填写自定义choicefield表单,python,django,forms,choicefield,Python,Django,Forms,Choicefield,我是DJango的新手,我试图用自定义数据填充choicefield表单,但我遇到了一个我不太理解的错误 在我的视图.py上,我有: def simpleDeploy(request): networkList = getDetailsNetworkPartitions(request) policiesList = getDetailsApplicationPolicies(request) if request.method == 'POST': ab

我是DJango的新手,我试图用自定义数据填充choicefield表单,但我遇到了一个我不太理解的错误

在我的
视图.py上,我有:

def simpleDeploy(request):
    networkList = getDetailsNetworkPartitions(request)
    policiesList = getDetailsApplicationPolicies(request)
    if request.method == 'POST':
        abs(5) #Don't do nothing by the moment, I need put something or I get an error
    else:
        simpleForm = SimpleDeploy(netList=networkList, polList=policiesList)
    return render(request, 'apacheStratos/simpleDeploy.html', {'form': simpleForm})
我的
forms.py
是:

class SimpleDeploy(forms.Form):
    def __init__(self, networkList, policiesList, *args, **kwargs):
        super(SimpleDeploy, self).__init__(*args, **kwargs)
        if networkList and policiesList:
            self.fields['networkPartitions'] = forms.ChoiceField(choices=networkList)
            self.fields['applicationPolicies'] = forms.ChoiceField(choices=policiesList)
        else:
            self.fields['networkPartitions'] = forms.ChoiceField(choices='No network partitions found')
            self.fields['applicationPolicies'] = forms.ChoiceField(choices='No application policies found')
Django抛出的错误是:
\uuuu init\uuuuuuu()在
simpleForm=SimpleDeploy(netList=networkList,polList=policiesList)行上至少接受3个参数(1个给定)

我不知道为什么会说,如果我通过了2,那么接受3个参数,然后给出1

我做错了什么?谢谢

编辑以放置错误和回溯:

错误:

TypeError at /stratos/simpleDeploy

__init__() takes at least 3 arguments (1 given)

Request Method:     GET
Request URL:    http://127.0.0.1:8000/stratos/simpleDeploy
Django Version:     1.8.12
Exception Type:     TypeError
Exception Value:    

__init__() takes at least 3 arguments (1 given)

Exception Location:     /home/iago/Escritorio/tfm/website/apacheStratos/views.py in simpleDeploy, line 60
Python Executable:  /usr/bin/python2.7
Python Version:     2.7.6
Python Path:    

['/home/iago/Escritorio/tfm/website',
 '/usr/local/lib/python2.7/dist-packages/Django-1.8.12-py2.7.egg',
 '/home/iago/Escritorio/tfm/website',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

Server time:    Thu, 14 Jul 2016 11:39:42 +0000
回溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/stratos/simpleDeploy

Django Version: 1.8.12
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'contact',
 'menu',
 'catalog',
 'apacheStratos')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.12-py2.7.egg/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/iago/Escritorio/tfm/website/apacheStratos/views.py" in simpleDeploy
  60.         simpleForm = SimpleDeploy(netList=networkList, polList=policiesList)

Exception Type: TypeError at /stratos/simpleDeploy
Exception Value: __init__() takes at least 3 arguments (1 given)

看起来您使用了不同的键,并且缺少位置参数。您发送的参数被视为
kwargs

在表单的
\uuuu init\uuuu
中,您需要以下参数

def __init__(self, networkList, policiesList, *args, **kwargs):
但是您发送时使用了键
netList
,以及
polList
,因此出现了错误

尝试:

甚至只是

simpleForm = SimpleDeploy(netList, polList)

请注意,我不知道您的局部变量名是什么,所以请相应地更新它们

看起来您使用了不同的键,并且缺少位置参数。您发送的参数被视为
kwargs

在表单的
\uuuu init\uuuu
中,您需要以下参数

def __init__(self, networkList, policiesList, *args, **kwargs):
但是您发送时使用了键
netList
,以及
polList
,因此出现了错误

尝试:

甚至只是

simpleForm = SimpleDeploy(netList, polList)

请注意,我不知道您的局部变量名是什么,所以请相应地更新它们

请显示完整的回溯。嗨,丹尼尔,我已经用信息更新了我的问题。请显示完整的回溯。嗨,丹尼尔,我用信息更新了我的问题。哦,似乎有效!!!谢谢但我得到一个:太多的值,无法在模板呈现期间解压{form.as_table}}上的错误。为什么?如果它是choicefiled,它应该接受带有选项的字符串列表。或者我错了。我想问题是,它需要一个元组列表。。您可能希望查看选项字段格式django表单,希望它是inAh,好的。我看看。谢谢哦,好像有用!!!谢谢但我得到一个:太多的值,无法在模板呈现期间解压{form.as_table}}上的错误。为什么?如果它是choicefiled,它应该接受带有选项的字符串列表。或者我错了。我想问题是,它需要一个元组列表。。您可能希望查看选项字段格式django表单,希望它是inAh,好的。我看看。谢谢