I'm creating a website with Django and am getting the following error when I try to submit POST data from a form (input has name 'bsubmit') in Firefox and IE9:
"Key 'bsubmit' not found in '<'QueryDict: {u开发者_如何学JAVA'bsubmit.y': [u'63'], u'bsubmit.x': [u'81'], u'csrfmiddlewaretoken':[u'bunchofnumbers']}>"
This works fine in Chrome, so I'm not really sure what it could be. Here how I'm processing it in the view:
def my_view(request):
if request.method == 'POST':
bsubmit = request.POST['bsubmit']
return render_to_response('my_template.html', {'bsubmit': bsubmit},
context_instance=RequestContext(request))
else:
bsubmit = 'some_val'
return render_to_response('my_template.html', {'bsubmit': bsubmit},
context_instance=RequestContext(request))
I feel like there has to be something obvious I'm missing but I'm sure what it could be.
EDIT: Here is the template...
<form action="/home/" method="post">
{% csrf_token %}
<input type="image" src="submit.jpg" id="value1" name="bsubmit" value="value1"/>
</form>
I originally had multiple submits, but the problem persists when I only use one.
Are you doing anything with the submit button with JavaScript? The inclusion of 'bsubmit.x' and 'bsubmit.y' in the request is very curious on its own.
That aside, what are you actually using 'bsubmit' for?
In general, you shouldn't be accessing post variables directly anyways. Use this instead:
bsubmit = request.POST.get('bsubmit') # defaults to `None`
-- OR --
bsubmit = request.POST.get('bsubmit', 'default')
That gets you around the error, so you just need to recover appropriately in your template.
精彩评论