저는 Django Rest Framework를 사용하여 사용자 등록/로그인으로 webapp를 구축하고 있습니다. 사용자가 CSRF 토큰이 필요하지 않은보기를 면제하려고합니다. 이는 내 생각이 지금과 같은 모습입니다 :Django csrf_exempt가 SessionAuthentication과 함께 작동하지 않습니다.
class UserSignUpView(generics.CreateAPIView):
permission_classes = [] # FIXME: doesn't seem to be working
serializer_class = UserSerializer
@method_decorator(csrf_exempt)
def post(self, request, *args, **kwargs):
super().post(self, request, *args, **kwargs)
def get_permissions(self):
if self.request.method == 'POST':
return (permissions.AllowAny(), TokenHasReadWriteScope())
return False
내 settings.py은 다음과 같습니다
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}
난 아직도 내 백엔드 출력 Forbidden (CSRF cookie not set.): /users/
에이를 얻고 앞에 고전 CSRF verification failed. Request aborted.
왜 작동하지 않습니까? CSRF 쿠키를 수동으로 설정하지 않은 것과 관련이있을 수 있습니까?
get_permissions는 장식자를 필요로하지 않습니다. csrf_exempt? POST 메소드를 사용 중입니다. @csrf_exempt는 다음과 같이 작성할 수 있습니다. [Documentation] (https://docs.djangoproject.com/en/1.10/ref/csrf/#django.views.decorators.csrf.csrf_protect) – Wilfried
[이 게시물] (http : //stackoverflow.com/questions/17716624/django-csrf-cookie-not-set) – Wilfried
@Wilfried'get_permissions'의 맨 위에'@method_decorator (csrf_exempt)'를 추가하려고했지만 아무런 변화가 없었습니다. –