티스토리 뷰
728x90
Spring과 마찬가지로 Django에서도 Vue와 REST API 통신을 할 때 다음과 같이 CORS 에러가 발생한다.
Access to XMLHttpRequest at 'http://localhost:5000/matching/users' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Django의 settings.py에서 CORS 설정을 추가해주면 해결된다.
✔️ 허용하고 싶은 origin을 list 형태로 넣을 수 있다.
# settings.py
INSTALLED_APPS = [
'corsheaders',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
]
# CORS 설정
CORS_ORIGIN_WHITELIST = ['http://localhost:8080']
CORS_ALLOW_CREDENTIALS = True
Ref.
Django CORS 설정하기 (tistory.com)
728x90
댓글
공지사항
최근에 올라온 글