django-html-validator
django-html-validator copied to clipboard
KeyError: 'content-type' when response['Content-Type'] is not set
AFAIU response['Content-Type'].startswith('text/html')
in middleware.py
should be replaced with 'text/html' in response.get('Content-Type', '')
.
Really? What kind of Content-Type do you have that doesn't start with text/html
?
It's just None
somehow. I'm using ListAPIView
and a CSV renderer from rest_framework_csv
.
Oh I see. Perhaps something like this instead:
if response.get('Content-Type', '').startswith('text/html'):
What do you think?
Looks like it would also work, yes
Cool. Make a PR with a unit test and I'll merge it.
Don't forget to comment about why sometimes the response
doesn't have a Content-Type
header.