fastapi跨域

1.不要用*号代替origins
2.不要用本地html做跨域测试,要用web服务测。 

app = FastAPI()

origins = [
    "http://localhost",
    "http://localhost:7146",
    "http://localhost:1880",
    "http://localhost:80",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

你可能感兴趣的:(python,fastapi,前端)