允许本地 Vite(5173/127.0.0.1) 跨域访问线上接口。

补充 CORS 与 CSRF_TRUSTED_ORIGINS,便于客服后台 localhost 联调。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-14 02:57:45 +08:00
parent 685c65691f
commit ca4b52217f

View File

@@ -188,18 +188,20 @@ REST_FRAMEWORK = {
}
# CORS settings
# CORS settings(本地 Vite 客服后台 + 线上域名)
CORS_ALLOWED_ORIGINS = [
"http://localhost:8080", # 假设前端开发服务器地址
"http://localhost:8080",
"http://127.0.0.1:8080",
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:5174",
"http://127.0.0.1:5174",
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://121.4.54.129",
"https://wenhe.nmslb.com:9187",
"https://wenhe.nmslb.com:4321",
"http://localhost:5173",
"http://localhost:5174"
"https://wenhe.nmslb.com",
]
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = (
@@ -222,6 +224,19 @@ CORS_ALLOW_HEADERS = [
"x-requested-with",
]
# Django 4+:前端带 Cookie/凭证跨域访问时需要信任来源
CSRF_TRUSTED_ORIGINS = [
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:5174",
"http://127.0.0.1:5174",
"http://localhost:8080",
"http://127.0.0.1:8080",
"https://wenhe.nmslb.com",
"https://wenhe.nmslb.com:9187",
"https://wenhe.nmslb.com:4321",
]
# 【待确认】自定义用户模型,你需要在 yonghu/models.py 中创建 class Yonghu
#AUTH_USER_MODEL = 'yonghu.Yonghu'