Django Python rest framework, No 'Access-Control-Allow-Origin' header is present on the requested resource in chrome, works in firefox Django Python rest framework, No 'Access-Control-Allow-Origin' header is present on the requested resource in chrome, works in firefox google-chrome google-chrome

Django Python rest framework, No 'Access-Control-Allow-Origin' header is present on the requested resource in chrome, works in firefox


Install the cors-headers package with

pip install django-cors-headers

Adds to your installed apps

INSTALLED_APPS = [    ...    'corsheaders',    ...]

Add on your MIDDLEWARE remember to add as being the first in the list

MIDDLEWARE = [      'corsheaders.middleware.CorsMiddleware',    'django.middleware.common.CommonMiddleware',    ...]

Before installed apps put this configuration for anyone to access

CORS_ORIGIN_ALLOW_ALL=True

Or create a list of hits

CORS_ORIGIN_WHITELIST = [    'http://google.com',    'http://hostname.example.com',    'http://localhost:8000',    'http://127.0.0.1:9000']


Check your request URL first. I had this problem when while using vue-resource. In my case, the error was a missing '/' at the end of url.


Make sure use 127.0.0.1 NOT localhost because when using localhost browser may look up an IPv6 address...or set up localhost to explicitly to 127.0.0.1 at /etc/hosts