django:ValueError need more than 1 value to unpack -
i'm using ajax , django dynamically populate combo box. ajax component works fine , parse data view int view, when i'm using spiting function gives me exception called "value error:need more 1 value unpack ". can helps me figure out error :) :) code:
def dropdownpopulate(request): if request.method=='post' : key = request.post['id'] else: key="" level, tree_id=key.split(",") next_nodes=structure.objects.filter(tree_id=key[tree_id]).filter(level=key[level]) context={'name':next_nodes} return render_to_response('renderajax.html',context)
this because s.split(',')
returning list of length 1
:
level, tree_id = key.split(',')
make sure return list of length 2
:
parts = key.split(',') if len(parts) == 2: level, tree_id = parts elif len(parts) == 1: level = parts[0] tree_id = none else: # level = tree_id = none pass
the apply filter this:
next_nodes = structure.objects.all() if level: next_nodes = next_nodes.filter(level=level) if tree_id: next_nodes = next_nodes.filter(tree_id=tree_id)
Comments
Post a Comment