I need to send cross-domain request with ajax to an app build with django rest framework (DRF). I'm aware that I need the csrf token to allow the request but not sure how to implement it.
Where in the flow do I obtain the token?
You need to pass the CSRF token along with any POST requests.
You can learn how to get this in Javascript at https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ ; there's a complete code sample there.
i think this is not possible since the purpose of the csrf_token is to prevent cross site request forgeries. here is the link https://docs.djangoproject.com/en/dev/ref/contrib/csrf/
though if you have access to the django app, you can put csrf_exempt decorator so that it accepts POST request even without crsf_token.
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.