Django ALLOWED_HOSTS 与 CORS(django-cors-headers)
Django ALLOWED_HOSTS vs CORS(django-cors-headers)
ALLOWED_HOSTS 和 CORS 有什么区别。如果我定义了 ALLOWED_HOSTS 是否还需要定义 CORS?我没有使用 Django 模板。
另外我有可能动态定义这两个吗?(我认为没有)
我正在使用 django 作为后端,并在不同的主机上使用多个 reactjs 前端应用程序。
ALLOWED_HOSTS 上的文档。
简而言之,在您拥有 DEBUG=FALSE
的生产环境中,您的 Django 应用程序将不会在 ALLOWED_HOSTS 中未指定的域或子域中提供服务。它是您可以在其上提供您的应用程序的受信任域的白名单。
CORS on the other hand, I'm assuming you are asking because you are also doing Django Rest Framework, stands for Cross-Origin Resource Sharing, basically allows your frontend apps, like the one you mentioned multiple reactjs apps, to interact with your APIs without having to deploy all of them on a same domain. django-cors-header是配置CORS的推荐包。
ALLOWED_HOSTS 和 CORS 有什么区别。如果我定义了 ALLOWED_HOSTS 是否还需要定义 CORS?我没有使用 Django 模板。
另外我有可能动态定义这两个吗?(我认为没有)
我正在使用 django 作为后端,并在不同的主机上使用多个 reactjs 前端应用程序。
ALLOWED_HOSTS 上的文档。
简而言之,在您拥有 DEBUG=FALSE
的生产环境中,您的 Django 应用程序将不会在 ALLOWED_HOSTS 中未指定的域或子域中提供服务。它是您可以在其上提供您的应用程序的受信任域的白名单。
CORS on the other hand, I'm assuming you are asking because you are also doing Django Rest Framework, stands for Cross-Origin Resource Sharing, basically allows your frontend apps, like the one you mentioned multiple reactjs apps, to interact with your APIs without having to deploy all of them on a same domain. django-cors-header是配置CORS的推荐包。