当前位置:网站首页>17_ Form Data
17_ Form Data
2022-07-26 02:11:00 【Empty nest youth_ rui】
17_ The form data
This section describes how to use Form Declare form data input parameters .
When we need to pass JSON When receiving field data , You can use forms Form.
To use forms , You need to install python-multipart
pip install python-multipart
Then you can go from fastapi Import Form Used :
from fastapi import FastAPI, Form
1. Definition Form Parameters :
create form (Form) Parameter mode and Body, Query equally :
from fastapi import FastAPI, Form
app = FastAPI()
@app.post("/login/")
async def login(username: str = Form(), password: str = Form()):
return {
"username": username}
for example ,OAuth2 canonical “ Cryptoflow ” The mode specifies to send... Through form fields username and password. It requires that the field must be named username and password, And send... Through the form field , Out of commission JSON.
Use Form Can declare and Body( And Query, Path, Cookie) Same metadata and validation .
explain :
FormIt is directly inherited fromBodyClass .
Be careful :
Declare that the form body should explicitly use
Form, otherwise ,FastAPI Parameters will be treated as query parameters or request body (JSON) Parameters .
2. About “ form field ”:
And JSON Different , HTML Forms (<form></form>) Data sent to the server is usually encoded in a special way .
FastAPI Make sure you read the data from the correct location , Instead of reading JSON.
Technical details :
Form data “ Media type MIME” The code is generally
application/x-www-form-urlencoded.But the form containing the file is encoded as
multipart/form-data. Document processing will be described later .For details of codes and form fields, see MDN web Document POST Section .
Warning :
Multiple... Can be declared in one path operation
FormParameters , But you can't declare to receive at the same time JSON OfBodyField . Because the code of the request body isapplication/x-www-form-urlencoded, Noapplication/json.This is not FastAPI The problem of , It is HTTP Provisions of the agreement .
边栏推荐
- Leetcode algorithm 147. insert and sort the linked list
- Arm assembly foundation of SOC
- TI AM335x工控模块网络跟文件系统NFS的实现
- 1. Mx6ul core module uses serial EMMC read / write test (IV)
- Programming basic environment variable setting of in-house SOC
- [C language brush leetcode] 814. Binary tree pruning (m)
- LeetCode302场周赛第三题--裁剪数字后查询第 K 小的数字
- National standard gb28181 protocol video platform easygbs message pop-up mode optimization
- 1. Mx6ul core module use serial RTC test (XII)
- 1. Mx6ul core module uses serial can and buzzer test (XI)
猜你喜欢

Ti am335x industrial control module uses the Debian system of beaglebone (BBB)

图解B+树的插入过程

1. Mx6ul core module uses serial can and buzzer test (XI)
![[2021] [paper notes] 6G technology vision - otfs modulation technology](/img/50/577ad05bc16e80d1c68eec7b6da988.png)
[2021] [paper notes] 6G technology vision - otfs modulation technology

I.MX6UL核心模块使用连载-Iot-6ULX核心模块简要介绍 (一)

Be careful about bitmap, the "memory Assassin"~

Implementation of Ti am335x industrial control module network and file system nfs
![[2020] [paper notes] growth of bi2te3/cofeb double-layer heterojunction by magnetron sputtering——](/img/5d/7d26e2d0d832c95e1cc011995ce774.png)
[2020] [paper notes] growth of bi2te3/cofeb double-layer heterojunction by magnetron sputtering——

SQL manual blind injection and error reporting injection

Acwing 379. hide and seek problem solution (minimum path non repeating point coverage)
随机推荐
LeetCode_动态规划_中等_264.丑数 II
2. Login - verification code function and saving login status
G2. passable paths (hard version) (tree diameter + LCA)
我来图书馆小程序一键签到和一键抢位置工具
Ti AM335X工控模块矩阵键盘电路的设计与驱动移植
[C language brush leetcode] 735. Planetary collision (m)
Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
Remember a laravel problem script @php artist package:discover handling the post autoload dump event returned with
图解B+树的插入过程
Navica tool imports remote MySQL into local MySQL database
[2019] [paper notes] tunable THz broadband absorption based on metamaterials——
Sqlyog data import and export graphic tutorial
[2021] [paper notes] 6G technology vision - otfs modulation technology
[C language brush leetcode] 814. Binary tree pruning (m)
17_表单数据
Implementation of Ti am335x industrial control module network and file system nfs
商业智能BI全解析,探寻BI本质与发展趋势
登堂入室soc之编程基础环境变量设置
[C language brush leetcode] 1462. curriculum IV (m)
Turn: do the right thing efficiently