I am writing a django application where I have a model called Website
which contains websites of people. I only allow people who have their websites in my database to use my Django REST API. I am using the django-cors-headers
package to whitelist the domains of people: https://github.com/adamchainz/django-cors-headers.
CORS_ORIGIN_WHITELIST
variable in settings.py allows me to white list domains as shown in https://github.com/adamchainz/django-cors-headers#cors_origin_whitelist
The problem is that I have to query my models to get the website domains, append them to a list and then put that list into CORS_ORIGIN_WHITELIST
. But I can't do that in settings.py because models are loaded after the app starts and settings.py is the one that starts the app.
Does anyone know a way around that? Any suggestions will be appreciated. Thanks in advance.