Fall back to parsing request body as JSON for form data

apparently that's what we'll be dealing with from Vue.js AJAX requests?
This commit is contained in:
Lance Edgar 2019-06-04 17:57:48 -05:00
parent 5c28f10921
commit c24098a117

View file

@ -889,7 +889,18 @@ class Form(object):
del self.validated del self.validated
if self.request.method != 'POST': if self.request.method != 'POST':
return False return False
# we assume data is in the form of POST params
controls = self.request.POST.items() controls = self.request.POST.items()
# but if not, we can try to parse request body as JSON
if not controls:
try:
controls = self.request.json_body.items()
except ValueError:
# not a valid JSON body, so no data
controls = []
dform = self.make_deform_form() dform = self.make_deform_form()
try: try:
self.validated = dform.validate(controls) self.validated = dform.validate(controls)