Reputation: 13
I have a field called 'approvedamount
' in a django form that is being populated in the browser but is not coming through in the request.POST values.
If you do a view on the QueryDict of the request variables upon Post, it shows the value is there (5000) - as such:
QueryDict: QueryDict: {u'csrfmiddlewaretoken': [u'bec667f48284f2478fa91bd54c2ca706', u'bec667f48284f2478fa91bd54c2ca706'], u'approve': [u'approved', u'approved'], u'submit_approval_update_15884': [u'Update'], u'declinecode': [u'Please Select', u'Please Select'], u'approvedamount': [u'5000', u'']}
however if you do a request.POST['approvedamount']
or request.POST.get('approvedamount')
the null string is returned
i've also verified in chrome debug tools that the value of the input box is set, it's just not coming through on the postback to Django for some reason.
Upvotes: 0
Views: 2518
Reputation: 1718
If the form was built from a template, then, your approvedamount
should include the name
attribute. It should be something like this:
<input class="form-field" name="approvedamount">
Upvotes: 0
Reputation: 10177
There seems to be something wrong with your form since many values are set two times in the QueryDict. u'approvedamount': [u'5000', u'']
shows you that you have two values for u'approvedamount and the second one is empty. By default QueryDict's get()
gives you the latter one, which is empty.
You should probably fix your form, but If you want to use the first of the submitted values you can use getlist
:
request.POST.getlist('approvedamount')[0]
Upvotes: 3