작성
·
607
답변 2
2
안녕하세요. 독자님.
보통은 발생하지 않으나, 독자님처럼 브라우저를 바꾸는 경우 등 특별한 경우에, csrftoken 이 없는 경우가 발생합니다.
이런 경우는 독자님 해결방안 처럼, edge 에서 chrome 으로 복사해 줘도 되고,
장고에서 정식 해결 방안이 있습니다.
아래와 같이 ensure_csrf_cookie 데코레이터를 사용해서, 강제로 csrftoken 을 만들어주면 됩니다.
========================================================
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie
@method_decorator(ensure_csrf_cookie, name='dispatch')
class ApiPostLV(BaseListView):
(이하 동일)
0
크롬에는 axios.defaults.xsrfCookieNmae = "csrftoken" 이런식의 지정 방식이 안 먹히는거 같습니다. edge에서 csrf token 값이랑 session id 를 복사해서 chrome cookie에 직접 넣어주면 작동합니다.