django-rest-frameworkdjango-cors-headers

Disable CORS for 2 paths


I'm using django-cors-header for CORS, I want to disable CORS (allow all) for 2 routes

(ex: /api/test1/, /api/test2) 

other route is still enable CORS (only allow for CORS_ORIGIN_WHITELIST host

Are there any way to do that ?

I've tried to set CORS_URLS_REGEX but then all route cannot be accessed

CORS_URLS_REGEX = r'^(?!(/api/test1/|/api/test2/).*'

Solution

  • Try this regex. I think it can help: ^(?!(/?api/test1/?$|/?api/test2/?$)).*

    I've checked this regex pattern on the website regex101 and it was okay.