19
loading...
This website collects cookies to deliver better user experience
http
, https
), domain(e.g. somedomain.com
, localhost
), and port(e.g. 80
, 443
, 3000
, 8000
).http://localhost
http://localhost:8000
https://localhost
OPTIONS
, which is a type of HTTP methods.GET
HEAD
POST
Accept
Accept-Language
Content-Language
Content-Type
application/x-www-form-urlencoded
, multipart/form-data
, text/plain
are allowed as valuesXMLHttpRequest
object, no event listeners are registered on the object returned by the XMLHttpRequest.upload
property used in the requestReadableStream
object is used in the request.pip install django-cors-headers
# settings.py
ALLOWED_HOSTS = ['*'] # '*' is a wildcard which allows any host
INSTALLED_APPS = [
...
'corsheaders',
...
]
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
...
]
# CORS settings
CORS_ORIGIN_ALLOW_ALL=True
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
)
CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
)
# main.py
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
pip install -U flask-cors
# main.py
from flask-cors import CORS
app = Flask(__name__)
CORS(app)