from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel
app = FastAPI()
class User(BaseModel):
username: str
password: str
'''
响应头 Response
'''
# @app.post("/login")
# def login(response: Response):
# response.headers["x-jwt-token"] = "This is jwt-token"
# response.headers.append("x-token","This is token")
@app.post("/login")
def login(user: User):
response = JSONResponse(
{
"username": user.username,
"password": user.password
},
status_code=201,
headers={"x-jwt-token": "value"}
)
return response
标签:20,FastAPI,app,响应,token,import,login,response
From: https://www.cnblogs.com/leoshi/p/17254379.html