4👍
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.
4👍
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
"corsheaders.middleware.CorsMiddleware",
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
In settings.py, if I arrange my MIDDLEWARE
array like this, it will work fine.
But if I move corsheaders.middleware.CorsMiddleware
to the last line, that error will occur
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)
- Django: Does "primary_key=True" also mean "unique"?
- Django heroku static dir
3👍
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 a
response with the status code in either 301 Moved Permanently", "307
Temporary 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
0👍
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')),
)