jm_p_op
aws Django 서버 배포하기 -4 admin csrf 토큰 넣기 본문
참고자료 https://pypi.org/project/django-cors-headers/
python버전, django 버전에 따라 설정방식이 다르다.
1. venv 실행시킨후
pip install django-cors-headers
2. 중복시 조심
settings.py
INSTALLED_APPS = [
...,
"corsheaders",
...,
]
MIDDLEWARE = [
...,
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
...,
]
3. 조건 3개중 하나 추가하기
- CORS_ALLOWED_ORIGINS (주소)
- CORS_ALLOWED_ORIGIN_REGEXES (정규표현)
- CORS_ALLOW_ALL_ORIGINS (전)
CORS_ALLOWED_ORIGINS = [
"https://example.com",]
CORS_ALLOWED_ORIGIN_REGEXES = [
r"^https://\w+\.example\.com$",
]
CORS_ALLOW_ALL_ORIGINS=TRUE
CSRF 설정
CORS_ALLOWED_ORIGINS = [
"https://read-only.example.com",
"https://read-and-write.example.com (도메인)",
]
CSRF_TRUSTED_ORIGINS = [
"https://read-and-write.example.com (도메인)",
]
'서버 > aws' 카테고리의 다른 글
Instance - Security Groups (0) | 2023.06.03 |
---|---|
LoadBalancer - Security Groups (0) | 2023.06.02 |
aws Django 서버 배포하기 -3(http=>https 업그레이드 (0) | 2023.05.28 |
aws Django 서버 배포하기 -2(서버에서 http포트로 Django 실행하기) (0) | 2023.05.21 |
SSH에서 서버 연결 (0) | 2023.05.19 |