简体   繁体   中英

API Django post url return 403 forbidden error

I am using rest-framework-api for my project and I am trying to create a User using an endpoint with a POST method. However, the response is always 403 Forbidden -> (CSRF token missing or incorrect.):

I have tried all the methods on stackoverflow : csrf_exempt decorators, authentication_classes = [], CsrfExemptMixin

And none of these methods works ... I always get the same answer "403 Forbiddden"

PS : I am sending request with POSTMAN

API :


    permission_classes = (AllowAny,) 
    authentication_classes = []
    # Serializer class to validate input and serialize output
    # Can be overridden by get_serializer_class()
    queryset = User.objects.all()
    serializer_class = UserSerializer`

Url:

api.register(r'auth/sign-up', views.UserEP, basename='userEP')

My aim is just to implement an endPoint that allows any user to create an account.

Simply just remove csrf middleware from your project settings. this will solve the problem. below is the actual name of that middleware:
'django.middleware.csrf.CsrfViewMiddleware'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM