python - Django 1.6: MultiValueDictKeyError in dropdown form -



python - Django 1.6: MultiValueDictKeyError in dropdown form -

i'm trying implement 2 dropdown menus in 1 of template maintain error.

traceback: file "/library/python/2.7/site-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/library/python/2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view 57. homecoming view_func(*args, **kwargs) file "views.py" in doclistings 91. request.session["genderselect"] = request.post['genderselect'] file "/library/python/2.7/site-packages/django/utils/datastructures.py" in __getitem__ 301. raise multivaluedictkeyerror(repr(key)) exception type: multivaluedictkeyerror @ /doclistings/ exception value: "'genderselect'"

here template i'm trying have 2 dropdown menus in 1 single form work

class="lang-html prettyprint-override"><form action="" method="post" > <select class="form-control" id="selection" name="selection"> <option><b>find doctor...</b></option> {% value, text in form.selection.field.choices %} <option value="{{ value }}">{{ text }}</option> {% endfor %} </select> <select class="form-control" id="genderdropdown" name="genderdropdown"> <option><b>select gender</b></option> {% value, text in form.genderselect.field.choices %} <option value="{{ value }}">{{ text }}</option> {% endfor %} </select> <span class="input-group-btn"> <button class="btn btn-primary" type="submit" name="submit" id="ss-submit">search</button> </span> </div> {% csrf_token %} </form>

here views i'm getting error

def doclistings(request): d = getvariables(request) if request.method == "post": form = dropdownselectionform(request.post) print form.errors if form.is_valid(): selection = form.cleaned_data['selection'] genderselect = form.cleaned_data['genderselect'] d['usergendselect'] = genderselect request.session["selection"] = request.post['selection'] homecoming httpresponseredirect('/doclistings') else: form = dropdownselectionform() s_name = request.session.get('selection') # alter variable name d['userselection'] = s_name # update new variable name gend = doctor.objects.get(gender = genderselect) spec = specialization.objects.get(name=s_name) # spec object doctors = doctor.objects.filter(specialization = spec, gender = gend).order_by('-likes') d['doctors'] = doctors d.update({'form': form}) homecoming render_to_response('meddy1/doclistings.html',d)

here doc model

class doctor(models.model): name = models.charfield(max_length=100) specialization = models.foreignkey(specialization) clinic = models.foreignkey(clinic) seekers = models.manytomanyfield(user, through='usercontent') gender_choices = ( ('male', 'male'), ('female','female'),) gender = models.charfield(max_length=15, choices = gender_choices, null=true, blank = true) image = models.imagefield(upload_to='uploads/', null=true, blank = true) mimetype = models.charfield(max_length=20) likes = models.integerfield(default=0)

python django drop-down-menu

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -