1

I am trying to create a multiple choice with checkboxes. I got the data displaying in checkboxes but when I submit I get the following error:

Template error: too many values to unpack

I read that the problem for some guys was they did not create 2tuples as elements of the choices list. But this does not seem the case. What could the problem be?

forms.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

views.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})
Rocco Ghielmini
  • 303
  • 5
  • 10

2 Answers2

5

Compare these:

form = Test(request.POST)

def __init__(self, options, ...

You're passing request.POST as the options argument.

Try this:

form = Test(data=request.POST)
Pavel Anossov
  • 60,842
  • 14
  • 151
  • 124
-2

how can unpack this code i test it with all eval unpacker but its not decode

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,{})) 
lennon310
  • 12,503
  • 11
  • 43
  • 61