Configuring Django CORS Headers
This page goes over how to configure Django CORS headers: setting up middleware, and CORS allowed origins in your Django project settings file.
This step is necessary if your API requests are coming outside of the existing app. Like if your frontend code is separate (different domain, port, etc); it's own React project for example.
All you need to do is one more configuration/adjustment to your settings.py
file.
INSTALLED_APPS = [
# ...existing code...
'corsheaders',
# ...existing code...
]
MIDDLEWARE = [
# ...existing code...
'corsheaders.middleware.CorsMiddleware',
# ...existing code...
]
CORS_ALLOWED_ORIGINS = [
"http://localhost:3000",
"http://localhost:3001",
"https://bluebird-documentation.web.app",
"https://bluebird-documentation.com"
]
The corsheaders
should already be installed from the previous steps, but if that isn't, you can install it via the below command.
pip3 install django-cors-headers
Part of: Django Email Client