Skip to content

Instantly share code, notes, and snippets.

@gauravv7
Created November 28, 2018 11:32
Show Gist options
  • Select an option

  • Save gauravv7/1786e4d382d03664c05341044bf95f7a to your computer and use it in GitHub Desktop.

Select an option

Save gauravv7/1786e4d382d03664c05341044bf95f7a to your computer and use it in GitHub Desktop.
a good way to print django request details
def pretty_request(request):
headers = ''
for header, value in request.META.items():
if not header.startswith('HTTP'):
continue
header = '-'.join([h.capitalize() for h in header[5:].lower().split('_')])
headers += '{}: {}\n'.format(header, value)
return (
'{method} HTTP/1.1\n'
'Content-Length: {content_length}\n'
'Content-Type: {content_type}\n'
'{headers}\n\n'
'{body}'
).format(
method=request.method,
content_length=request.META['CONTENT_LENGTH'],
content_type=request.META['CONTENT_TYPE'],
headers=headers,
body=request.body,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment