1

I need to access a djangorestframework api but because the django server uses CSRF token and i cant get past it. How can i configure djangorestframework to override the djangorestframework and not be redirected to login?

Im new to this so i need help.

accessing the django rest framework would be a pure python program which runs in the background of a client pc collecting data so i need to use urllib2 or request for this. any ideas?

1
  • you want CSRF. So find out how to generate a token, create a REST endpoint that delivers it. Then on the client side include that token in subsequent requests. Commented Feb 10, 2015 at 14:26

1 Answer 1

1

The API needs to expose an authentication method for your client to use.

The SessionAuthentication style requires CSRF validation and is suuitable for javascript based clients, running in the context of a logged-in application. If this describes the sort of client access you're making then read the Django documentation on CSRF and AJAX requests, which describes how to pass a CSRF token to a javascript based client.

Other schemes such as TokenAuthentication do not require CSRF validation, and will successfully authentication without passing any CSRF token.

Make sure that you know what schemes the API supports and choose the right one to use for your client access.

For more information see the authentication documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Tom, I am looking for a good example of a TokenAuthentication implementation with DRF, do you know any?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.