Мне нужно настроить белый список для политики CORS внутри моего приложения django. Вместо жесткого кодирования URL-адресов внутри settings.py , я хотел бы поместить их в отдельный файл, например, .env из django -environ . Это мой код:
.env
DEBUG=on
SECRET_KEY='xxx'
DATABASE_URL=psql://xxx
CORS_ORIGIN_WHITELIST=http://127.0.0.1:4200
settings.py ( MIDDLEWARE и INSTALLED_APPS в порядке)
...
environ.Env.read_env()
...
CORS_ORIGIN_WHITELIST = env('CORS_ORIGIN_WHITELIST')
Я получаю следующую ошибку:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/david/errepiu-project/backend/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/david/errepiu-project/backend/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/david/errepiu-project/backend/venv/lib/python3.7/site-packages/django/core/management/base.py", line 441, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (corsheaders.E013) Origin '.' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '.' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '.' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '/' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '/' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '0' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '1' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '1' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '2' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '2' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '4' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin '7' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin ':' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin ':' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin 'h' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin 'p' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin 't' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
?: (corsheaders.E013) Origin 't' in CORS_ORIGIN_WHITELIST is missing scheme or netloc
HINT: Add a scheme (e.g. https://) or netloc (e.g. example.com).
System check identified 21 issues (0 silenced).
Другие настройки внутри .env файла работают правильно. Я также пытался использовать одинарные / двойные кавычки для моего URL, но он все еще не работает.