how i dynamically populate to cors allowed origins in django rest framework

Solutions on MaxInterview for how i dynamically populate to cors allowed origins in django rest framework by the best coders in the world

showing results for - "how i dynamically populate to cors allowed origins in django rest framework"
Alberto
07 Nov 2019
1django-cors-headers has a signal that allows you to decide whether or not to allow the request to pass. The docs show exactly your use case.
2
3Note that CORS_ORIGIN_WHITELIST is also checked by the cors middleware (the signal response doesn't replace the white list), so you can have both: a static whitelist + a dynamic whitelist that depends on the request. You don't need to check the static whitelist in your signal handler.
4                                                                        
5                                                                        https://github.com/adamchainz/django-cors-headers