0

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.

2 Answers 2

3

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]
Sign up to request clarification or add additional context in comments.

Comments

0

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">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.