Redirect is not allowed for a preflight request Redirect is not allowed for a preflight request django django

Redirect is not allowed for a preflight request


You're being redirected to site.site.comapi/register/

Do you have some other middleware that does this? Maybe in Apache config?

Note it's a 301 so your browser has cached this response and will now always redirect there even if your rove the code that resulted in this redirect, or even if you stop Django from running.

So you will need to also clear your redirect cache in the browser.

This is why I don't like 301 responses. 302 are much more polite.


Just writing my story here in case anybody may have the same issue as mine.

Basically, this is a server end issue, so no need to change anything at the front end.

For this error message, it indicated that the OPTIONS requests got aresponse with the status code in either 301 Moved Permanently", "307Temporary Redirect", or "308 Permanent Redirect".

Please check your requested URL with the 'location' attribute from the OPTIONS response, see if they are the same or not.

For me, the issue was my request URL is **"https://server.com/getdata"**but the URL I set on the server was **"https://server.com/getdata/"**

then the server give me an 308 to correct it with the '/', this works for POST, GET and HEAD, but not OPTIONS.

I'm using flask, flask_restful and the flask_cors.

use this will also solve this redirect issue for me.

app.url_map.strict_slashes = False


I had the same problem until I discovered that the redirect was caused by the Django internationalization framework, where all urls get a i18n url extension such as /en/path_to_resource when actually path_to_resource was requested. The internationalization framework achieves this through a 302 redirect.

The solution to this problem is to keep the rest-api urls outside the section with the i18n_patterns. The resulting urls.py might then look like

urlpatterns = [    path('i18n/', include('django.conf.urls.i18n')),    path('rest/', include(('rest.urls', 'rest'), namespace='rest')),]urlpatterns += i18n_patterns(    path('admin/', admin.site.urls),    path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),    path('my_app/', include(('my_app.urls', 'my_app'), namespace='my_app')),)