mirror of
https://github.com/rjNemo/fastapi
synced 2026-06-12 13:36:41 +00:00
📝 Add notes about installing python-multipart for forms (#574)
This commit is contained in:
parent
fadfe4c586
commit
f4d753620b
4 changed files with 24 additions and 0 deletions
|
|
@ -1,5 +1,12 @@
|
||||||
You can define files to be uploaded by the client using `File`.
|
You can define files to be uploaded by the client using `File`.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
To receive uploaded files, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
|
||||||
|
|
||||||
|
E.g. `pip install python-multipart`.
|
||||||
|
|
||||||
|
This is because uploaded files are sent as "form data".
|
||||||
|
|
||||||
## Import `File`
|
## Import `File`
|
||||||
|
|
||||||
Import `File` and `UploadFile` from `fastapi`:
|
Import `File` and `UploadFile` from `fastapi`:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
You can define files and form fields at the same time using `File` and `Form`.
|
You can define files and form fields at the same time using `File` and `Form`.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
To receive uploaded files and/or form data, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
|
||||||
|
|
||||||
|
E.g. `pip install python-multipart`.
|
||||||
|
|
||||||
## Import `File` and `Form`
|
## Import `File` and `Form`
|
||||||
|
|
||||||
```Python hl_lines="1"
|
```Python hl_lines="1"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
When you need to receive form fields instead of JSON, you can use `Form`.
|
When you need to receive form fields instead of JSON, you can use `Form`.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
To use forms, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
|
||||||
|
|
||||||
|
E.g. `pip install python-multipart`.
|
||||||
|
|
||||||
## Import `Form`
|
## Import `Form`
|
||||||
|
|
||||||
Import `Form` from `fastapi`:
|
Import `Form` from `fastapi`:
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,13 @@ Copy the example in a file `main.py`:
|
||||||
|
|
||||||
## Run it
|
## Run it
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
First install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
|
||||||
|
|
||||||
|
E.g. `pip install python-multipart`.
|
||||||
|
|
||||||
|
This is because **OAuth2** uses "form data" for sending the `username` and `password`.
|
||||||
|
|
||||||
Run the example with:
|
Run the example with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue