Django REST Framework w/ TokenAuthentication issue with CSRF/CORS
<p>I am using TokenAuthentication in Django REST Framework to have a script remotely access my API. The domain running the API is behind a TLS certificate.</p>

<p>I have scoured through MANY sources, and tried many options before coming here to figure out what my problem is. In short, I continue to get the <code>CSRF verification failed. Request aborted.</code> error when I attempt to post.</p>

<p>Here is my view:</p>

<pre><code># @csrf_exempt
@api_view(['POST'])
@authentication_classes((TokenAuthentication,))
@permission_classes((permissions.IsAuthenticated,))
def create_object(request):
</code></pre>

<p><code>csrf_exempt</code> decorator has done nothing here. So, I have also tried it on my <code>urls.py</code>:</p>

<pre><code>url(r'^create_object/', csrf_exempt(views.create_object),),
</code></pre>

<p>I even tried writing a custom decorator, and using <a href="https://stackoverflow.com/a/32404315/1036843">this suggestion</a>. Even when I do this, I cannot even seem to get that decorator to execute before getting the failure. Perhaps there is an issue with the ordering of my middleware?</p>

<pre><code>'sslify.middleware.SSLifyMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',

'corsheaders.middleware.CorsMiddleware',

'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',

'corsheaders.middleware.CorsPostCsrfMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
</code></pre>

<p>Here are my django cors settings:</p>

<pre><code>CORS_ORIGIN_ALLOW_ALL = False 
CORS_ORIGIN_WHITELIST = ('example.com',) 
CORS_REPLACE_HTTPS_REFERER = True
</code></pre>