2π
β
I think the usual way is that your backend (api) will run on a separate server than your frontend and you make CORS
CORS
requests. Therfore you have to set the CORS-Header correctly. This is quite simple using django-cors-headers.
#settings.py
INSTALLED_APPS = (
...
'corsheaders',
...
)
MIDDLEWARE_CLASSES = (
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
)
CORS_ORIGIN_ALLOW_ALL = True # allows all
# or use whitelist:
CORS_ORIGIN_WHITELIST = (
'google.com',
'hostname.example.com'
)
If you develop for a website only, you could run frontend and backend on the same server. but if you develop a mobile app you canβt install and run django on the phone.
π€ilse2005
Source:stackexchange.com