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
request.body
request.data does not read the data stream again.
2.1m questions
2.1m answers
60 comments
57.0k users