I sufering from the problem with my code, whenever i entered my data into the database and then at time when i click submit it will through an error Multyvaluekeyerror. i change my form value so many times but nothing is working. Please help me out this.....it very be thankfull.
MultiValueDictKeyError at /admin/criminals
'gender'
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/criminals
Django Version: 2.2.4
Exception Type: MultiValueDictKeyError
Exception Value:
'gender'
Exception Location: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\datastructures.py in __getitem__, line 80
Python Executable: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.4
Python Path:
['D:\\django project\\gadmin3',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages']
Server time: Mon, 7 Oct 2019 04:35:54 +0000
MAIN FORM CODE:-
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Gender</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<div name="gender" id="" class="btn-group" data-toggle="buttons">
<label class="btn btn-default" data-toggle-class="btn-primary"
data-toggle-passive-class="btn-default">
<input type="radio" name="" value="male" data-parsley-
multiple="gender"> Male
</label>
<label class="btn btn-primary" data-toggle-class="btn-primary"
data-toggle-passive-class="btn-default">
<input type="radio" name="" value="female" data-parsley-
multiple="gender"> Female
</label>
</div>
</div>
</div>
VIEW SIDE CODE:-
def criminals(request):
if request.method=="POST":
cn = request.POST['crname']
ccrime = request.POST['crime']
cage = request.POST['age']
cheight=request.POST['height']
cbody = request.POST['bodymark']
crgen = request.POST['gender']
s= Criminals()
s.mname=cn
s.mcrime=ccrime
s.mage=cage
s.image = request.FILES['photo']
s.mheight=cheight
s.mbody=cbody
s.mgender=crgen
s.save()
messages.success(request,"Criminal Added Successfully.")
return render(request,'criminal.html')
else:
return render(request,'criminal.html')