紧身胸衣.E013 django-cors标头中出现错误



我试图打开端口,以便在'使用django后端作为APIhttp://localhost:3000'

这是我的

CORS_ALLOWED_ORIGINS = (
'http://localhost:3000'
)
INSTALLED_APPS = [
*
'corsheaders',
]
MIDDLEWARE = [
*
"corsheaders.middleware.CorsMiddleware",# new
"django.middleware.common.CommonMiddleware", # new
*
]

但我一直收到这样的错误信息

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (corsheaders.E013) Origin '/' in CORS_ALLOWED_ORIGINS is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '/' in CORS_ALLOWED_ORIGINS is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ALLOWED_ORIGINS is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ALLOWED_ORIGINS is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
.
.
.
.
.
.
System check identified 21 issues (0 silenced).

PS

python版本3.10.6

django 4.0.6版

django-cors头文件版本3.13.0

我认为您应该使用"["代替"(">

CORS_ALLOWED_ORIGINS = [
'http://localhost:3000'
]

我想这就行了。

如果你想允许所有来源,你可以试试这个:

CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True

最新更新