diff --git a/a_long_dianjing/settings.py b/a_long_dianjing/settings.py index 8488a12..8fc7307 100644 --- a/a_long_dianjing/settings.py +++ b/a_long_dianjing/settings.py @@ -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'