最新django-cors-headers配置项简述

配置

根据2022-2-12的readme.rst文档书写

在Django设置中配置中间件的行为。必须设置以下三种设置中的至少一种:

  • CORS_ALLOWED_ORIGINS
  • CORS_ALLOWED_ORIGIN_REGEXE
  • CORS_ALLOW_ALL_ORIGINS

CORS_ALLOWED_ORIGINS: Sequence[str]

允许的来源,默认为[]

CORS_ALLOWED_ORIGINS = [
    "https://example.com",
    "https://sub.example.com",
    "http://localhost:8080",
    "http://127.0.0.1:9000",
]

代替CORS_ORIGIN_WHITELIST

CORS_ALLOWED_ORIGIN_REGEXES: Sequence[str | Pattern[str]]

使用正则表达式的允许的来源

CORS_ALLOWED_ORIGIN_REGEXES = [
    r"^https://\w+\.example\.com$",
]

代替CORS_ORIGIN_REGEX_WHITELIST

CORS_ALLOW_ALL_ORIGINS: bool

如果为True,允许所有来源,默认为False
代替CORS_ORIGIN_ALLOW_ALL

先到这里,其他的配置以后再加