I had the same problem. django-cors-headers code, my error was as follows:
So far, the full CORS header looks like this (note the schema AND hostname):
Access-Control-Allow-Origin: https:
The value CORS_ORIGIN_WHITELIST requires it in a format that compares with urlparse.netloc ( docs ) Origin - a header that is only a host (possibly a port)
def origin_found_in_white_lists(self, origin, url): return ( url.netloc in conf.CORS_ORIGIN_WHITELIST or (origin == 'null' and origin in conf.CORS_ORIGIN_WHITELIST) or self.regex_domain_match(origin) )
So far, the RegEx whitelist compares it to the full Origin -header.
Thus, the correct configuration (as the example in the configuration guide correctly sets, but incorrectly describes):
CORS_ORIGIN_WHITELIST = ( 'example.com', )
What could be a problem if you do not want your API to talk to an insecure http version of the website. Use RegEx in this case.
Also note: during troubleshooting, it turned out that the CORS header is completely missing if no match is found. This means that the lack of a header is not a sure sign of a complete malfunction of the middleware, but perhaps just the wrong configuration.
Chris source share