Skip to content

Instantly share code, notes, and snippets.

@defrex
defrex / pretty_request.py
Last active September 8, 2023 14:33
A simple function to print a Django request the way requests are meant to be printed.
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 (