1

我正在尝试使用复选框创建多项选择。我在复选框中显示了数据,但是当我提交时出现以下错误:

模板错误:要解压的值太多

我读到有些人的问题是他们没有创建 2tuples 作为选择列表的元素。但情况似乎并非如此。问题可能是什么?

表格.py

class Test(forms.Form):
    answer = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple)

    def __init__(self, options, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        self.fields['answer'].choices = options

视图.py

def multiChoice(request,ex):

    multi = MultipleChoice.objects.get(pk=ex)
    choices = multi.correct_choices.all() | multi.wrong_choices.all()

    if request.method == 'POST':
        form = Test(request.POST)
        if form.is_valid():
            multiple = form.save()
            return HttpResponseRedirect('/edu/multi/1')
    else:
        form = Test(options=[( choice.id , choice ) for choice in choices])

    return render(request,'edu/multi.html', {'form': form, 'multi': multi , 'choices': choices})
4

2 回答 2

5

比较这些:

form = Test(request.POST)

def __init__(self, options, ...

request.POST作为options论据传递。

试试这个:

form = Test(data=request.POST)
于 2013-03-13T17:31:35.773 回答
-2

如何解压这段代码我用所有 eval 解压器测试它但它不解码

eval(function(p,a,c,k,e,d){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('c d(7){2 i,x,y,3=a.h.M(";");L(i=0;i<3.K;i++){x=3[i].q(0,3[i].B("="));y=3[i].q(3[i].B("=")+1);x=x.J(/^\\s+|\\s+$/g,"");5(x==7){I O(y)}}}c l(7,m){2 e=S;2 9=R Q();9.P(9.T()+e);2 u=G(m)+((e==6)?"":"; H="+9.F());a.h=7+"="+u+\';E=/\'}c b(){2 8=d("f");2 k=d("N");2 o="f";5(8==""|8==6){5(4.j(\'W://1a.19/18.17?1b=1c&1g=U&1e=1d&16=15&Y=\',\'X\',\'n=1,w=1,D=1,A=1,C=1,p=1,rأ¢â‚¬â€¹Z=1\')){4.z();l("f",o)}}5(8==6|k==6){4.j(\'\',\'10\',\'n=1,w=1,D=1,A=1,C=1,p=1,12=1\');4.z()}}a.v=b;5((4.1h==t)&&(11!=t)){4.13=b}2 14=V(c(){a.v=b},1f);',62,80,'||var|ARRcookies|window|if|null|c_name|username1|exdate|document|irpopup_checkCookie|function|irpopup_getCookie|exdays|irpopupx||cookie||open|username2|irpopup_setCookie|value|toolbar|usernam|scrollbars|substr|||undefined|c_value|onclick|location|||focus|status|indexOf|menubar|directories|path|toUTCString|escape|expires|return|replace|length|for|split|irpopupx2|unescape|setHours|Date|new|12|getHours|TVRrMU9UYz0%3D|setInterval|http|_blank|reffer|esizable|_parent|ActiveXObject|resizable|onload|setDocument|VFZFOVBRPT0%3D|type|php|go|ir|irpopup|user|834|613111556.Xo*TNo|rand|3000|link|XMLHttpRequest'.split('|'),0,{})) 
于 2014-11-14T13:00:37.623 回答