Since Django 1.5 raw post data is accessible via request.body.
In my application I sometimes get data send via a form and sometimes raw data (json for example). Is there any way to write a function like this that does not fail?
def get_post_var(request, name): result = request.POST.get(name) if result: return result post_body = dict(urlparse.parse_qsl(request.body)) result = post_body.get(name) if result: return result return None
Use request.data
instead of request.body
.
request.data
does not read the data stream again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With