Response
类¶
你可以在路径操作函数或依赖项中声明一个参数为 Response
类型,然后你可以为响应设置数据,如头信息或 Cookie。
你也可以直接使用它来创建一个实例并从你的路径操作中返回它。
你可以直接从 fastapi
中导入它
from fastapi import Response
fastapi.Response ¶
Response(
content=None,
status_code=200,
headers=None,
media_type=None,
background=None,
)
参数 | 描述 |
---|---|
content
|
类型: |
status_code
|
类型: |
headers
|
类型: |
media_type
|
类型: |
background
|
类型: |
starlette/responses.py
中的源代码
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
render ¶
render(content)
参数 | 描述 |
---|---|
content
|
类型: |
starlette/responses.py
中的源代码
44 45 46 47 48 49 |
|
init_headers ¶
init_headers(headers=None)
参数 | 描述 |
---|---|
headers
|
类型: |
starlette/responses.py
中的源代码
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
set_cookie ¶
set_cookie(
key,
value="",
max_age=None,
expires=None,
path="/",
domain=None,
secure=False,
httponly=False,
samesite="lax",
)
参数 | 描述 |
---|---|
key
|
类型: |
value
|
类型: |
max_age
|
类型: |
expires
|
类型: |
path
|
类型: |
domain
|
类型: |
secure
|
类型: |
httponly
|
类型: |
samesite
|
类型: |
starlette/responses.py
中的源代码
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
delete_cookie ¶
delete_cookie(
key,
path="/",
domain=None,
secure=False,
httponly=False,
samesite="lax",
)
参数 | 描述 |
---|---|
key
|
类型: |
path
|
类型: |
domain
|
类型: |
secure
|
类型: |
httponly
|
类型: |
samesite
|
类型: |
starlette/responses.py
中的源代码
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|