diff --git a/backend/conf/env.py b/backend/conf/env.py index 134c233ecde237be18b72e21b1e42dff0bcf8f22..3e487f63482d53bf34f2d8da724588d2752c01fc 100644 --- a/backend/conf/env.py +++ b/backend/conf/env.py @@ -30,3 +30,13 @@ ENABLE_LOGIN_ANALYSIS_LOG = True # 启动登录详细概略获取(通过调用a # 是否开启演示环境,开启后增 删 改功能失效 DEMO = False + +# 跨域配置 +if DEBUG: + CORS_ALLOW_ALL_ORIGINS = True + +# CORS_ALLOWED_ORIGINS = [ +# 'http://localhost:8080', +# 'http://127.0.0.1:8080', +# 'http://web.example.com' +# ] \ No newline at end of file diff --git a/backend/fuadmin/settings.py b/backend/fuadmin/settings.py index 267d1fc1b3053e7b6f9736b7c45eef105eac6f1c..52c1d87fba4073c7ca9896e7b63118946f30f64d 100644 --- a/backend/fuadmin/settings.py +++ b/backend/fuadmin/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'django_celery_beat', 'django_celery_results', 'system', @@ -46,6 +47,7 @@ INSTALLED_APPS = [ 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', diff --git a/backend/requirements.txt b/backend/requirements.txt index dd579f1543b98a1fb13427a664b3dcceea80410a..a3f9616fc14cffb9cda837fde1352a1201dea0d5 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -11,6 +11,7 @@ mysqlclient==2.1.0 # pyodbc==4.0.32 django-celery-beat==2.3.0 django-celery-results==2.3.1 +django-cors-headers==3.14.0 celery==5.2.7 pypinyin==0.46.0 user-agents==2.2.0