国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

FastAPI 基本使用(一)

這篇具有很好參考價值的文章主要介紹了FastAPI 基本使用(一)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

FastAPI 基本使用(一)

?

目錄

?編輯

1、基本介紹?

2、運行方式

3、創(chuàng)建接口步驟

4、自動生成API文檔

4.1 交互式API文檔

4.2?備用API文檔

5、FastApi 執(zhí)行順序

6、Python-Pydantic庫

6.1?BaseModel模型

6.2?請求體 + 路徑參數(shù) + 查詢參數(shù)

7、Query/Path/Body/Field 參數(shù)(額外的校驗) 與 字符串驗證

8、typing類型注解

8.1 常用類型提示

8.2 Optional 可選類型

8.3 Union 聯(lián)合類型

8.4?typing List

9、請求示例展示在接口文檔中

10 、Cookie,Header參數(shù)

11 、響應(yīng)模型 response_model

12 、響應(yīng)狀態(tài)碼-使用 status_code 參數(shù)來聲明

13 、Form表單數(shù)據(jù)

14 、上傳文件-File, UploadFile

15 、處理錯誤-HTTPException

16、jsonable_encoder() 函數(shù)

17 、依賴注入-Depends


1、基本介紹?

????????基于Python3.6+版本的、用于構(gòu)建API現(xiàn)代的、高性能的web框架。FastAPI是建立在Pydantic和Starlette基礎(chǔ)上的,Pydantic是一個基于Python類型提示來定義數(shù)據(jù)驗證、序列化和文檔的庫。Starlette是一種輕量級的ASGI框架/工具包,是構(gòu)建高性能Asyncio服務(wù)的理性選擇。

  1. Uvicorn 是一個閃電般快速的 ASGI 服務(wù)器,基于 uvloop 和 httptools 構(gòu)建。
  2. 實現(xiàn)一個基于ASGI(異步服務(wù)器網(wǎng)關(guān)接口)的最小應(yīng)用程序接口。
  3. Starlette 負(fù)責(zé) web 部分。
  4. Pydantic 負(fù)責(zé)數(shù)據(jù)部分。
  5. https://fastapi.tiangolo.com/zh/tutorial/first-steps/

2、運行方式

  1. 運行命令 uvicorn main:app --reload
  2. pycharm運行 (通過 uvicorn 命令行 uvicorn 腳本名:app對象--reload 參數(shù) 啟動服務(wù))
if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)

3、創(chuàng)建接口步驟

  1. 導(dǎo)入 FastAPI(from fastapi import FastAPI);
  2. 創(chuàng)建一個 app 實例(app = FastAPI());
  3. 編寫一個路徑操作裝飾器(如 @app.get("/"));
  4. 編寫一個路徑操作函數(shù)(如上面的?def?root():?...);
  5. 定義返回值運行開發(fā)服務(wù)器(如 uvicorn main:app --reload);

4、自動生成API文檔

4.1 交互式API文檔

在瀏覽器中請求?http://127.0.0.1:8000/docs?,顯示交互式API文檔, 自動交互式 API 文檔(由?Swagger UI?提供),如下圖:

FastAPI 基本使用(一)

4.2?備用API文檔

在瀏覽器中請求?http://127.0.0.1:8000/redoc?,顯示備用API文檔, 備用的自動交互式文檔(由?ReDoc?提供),如下圖:

FastAPI 基本使用(一)

?

5、FastApi 執(zhí)行順序

按照路徑順序匹配,默認(rèn)匹配的是第一個帶參數(shù)的路徑

6、Python-Pydantic庫

  1. pydantic庫是一種常用的用于數(shù)據(jù)接口schema定義與檢查的庫。
  2. 通過pydantic庫,我們可以更為規(guī)范地定義和使用數(shù)據(jù)接口。
  3. pydantic庫的數(shù)據(jù)定義方式是通過BaseModel類來進行定義的,所有基于pydantic的數(shù)據(jù)類型本質(zhì)上都是一個BaseModel類。調(diào)用時,我們只需要對其進行實例化即可。
  4. 是一個用來執(zhí)行數(shù)據(jù)校驗的python庫。
from pydantic import BaseModel

# schema基本定義方法
class Person(BaseModel):
    name: str

# 基本的schema實例化方法-直接傳入
p = Person(name="ABC123")
print(p.json())

>>> {"name": "ABC123"}

6.1?BaseModel模型

  1. 可以在代碼運行時強制執(zhí)行類型提示,并在數(shù)據(jù)校驗無效時提供友好的錯誤提示。
  2. 是一個解析庫,而不是驗證庫(簡單來說:pydantic保證輸出模型的類型和約束)
  3. 所有基于 pydantic 的數(shù)據(jù)類型本質(zhì)上都是一個 BaseModel 類
  4. 使用pydantic模型作請求體
  5. 需要安裝?pip install pydantic
  6. 使用時需要導(dǎo)入?from pydantic import BaseMode
from pydantic import BaseModel

class User(BaseModel):
    username: str
    email: Optional[str] = None
    full_name: Optional[str] = None
    status: Optional[bool] = None

6.2?請求體 + 路徑參數(shù) + 查詢參數(shù)

from typing import Union

from fastapi import FastAPI
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    description: Union[str, None] = None
    price: float
    tax: Union[float, None] = None

app = FastAPI()

"""
函數(shù)參數(shù)將依次按如下規(guī)則進行識別:
● 如果在路徑中也聲明了該參數(shù),它將被用作路徑參數(shù)(例如:item_id)。
● 如果參數(shù)屬于單一類型(比如 int、float、str、bool 等)它將被解釋為查詢參數(shù)(例如:q)。
● 如果參數(shù)的類型被聲明為一個 Pydantic 模型,它將被解釋為請求體(例如:item)。
"""

@app.put("/items/{item_id}")
async def create_item(item_id: int, item: Item, q: Union[str, None] = None):
    result = {"item_id": item_id, **item.dict()}
    if q:
        result.update({"q": q})
    return result

7、Query/Path/Body/Field 參數(shù)(額外的校驗) 與 字符串驗證

  1. body,Query,Path方法的父類都是直接或者間接的繼承FieldInfo,而Field就FieldInfo的實例化,F(xiàn)ieldInfo繼承了Representation,它們本質(zhì)上就是Representation類的子類。
  2. 從 fastapi 導(dǎo)入 Query、Path 等對象時,他們實際上是返回特殊類的函數(shù)。
  3. 使用Path提取和驗證路徑參數(shù);使用Query提取和驗證請求中的參數(shù);使用Body將參數(shù)讓客戶端由body(默認(rèn)application/json方式)傳入。
  4. Field 可用于提供有關(guān)字段和驗證的額外信息,如設(shè)置必填項和可選,設(shè)置最大值和最小值,字符串長度等限制
  5. 參數(shù)說明:
    1. Field(None) 是可選字段,不傳的時候值默認(rèn)為None
    2. Field(…) 是設(shè)置必填項字段
    3. title 自定義標(biāo)題,如果沒有默認(rèn)就是字段屬性的值
    4. description 定義字段描述內(nèi)容
    5. gt:大于(greater than)
    6. ge:大于等于(greater than or equal)
    7. lt:小于(less than)
    8. le:小于等于(less than or equal)
from fastapi import FastAPI, Query

# m是可選參數(shù),參數(shù)長度2-10,以name開頭
@app.get("/update_items/")
# 當(dāng)使用 Query 且需要聲明一個值是必需的時,可以將 ... 用作第一個參數(shù)值
# def update_items(m: Optional[str] = Query(..., max_length=10,min_length=2,regex="^name")):
def update_items(m: Optional[str] = Query(None, max_length=10,min_length=2,regex="^name")):
    results = {"items": [{"oneid": "北京"}, {"two": "上海"}]}
    if m:
        results.update({"上海": m})
    return results


"""
聲明數(shù)值校驗:
gt:大于(greater than)
ge:大于等于(greater than or equal)
lt:小于(less than)
le:小于等于(less than or equal)

regex正側(cè)參數(shù)的寫法:
以 ^ 符號開頭
以 $ 符號結(jié)尾

使用省略號(...)聲明必需參數(shù)
"""

# 需求:id大于5才能返回
@app.get("/id")
async def read_id(*, id: int = Query(..., ge=5, ), q_value: str):
    results = {"message": f"{q_value}"}
    if id:
        results.update({"new_value": q_value})
    return results

"""
● 傳遞 * 作為函數(shù)的第一個參數(shù),
● 如果單獨出現(xiàn)星號 *,
● 則星號 * 后的參數(shù)必須用關(guān)鍵字傳入
"""

@app.get("/items/{item_id}")
# 使用 Path 為路徑參數(shù)聲明相同類型的校驗和元數(shù)據(jù)
async def read_items(*, item_id: int = Path(title="The ID of the item to get"), q: str):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results


"""
●嵌入單個請求體參數(shù),期望一個擁有 item 鍵并在值中包含模型內(nèi)容的 JSON,
●返回如下:
{
    "item": {
        "name": "Foo",
        "description": "The pretender",
        "price": 42.0,
        "tax": 3.2
    }
}
●可以使用一個特殊的 Body 參數(shù) embed : item: Item = Body(embed=True)
"""

class Item(BaseModel):
    name: str
    description: Union[str, None] = None
    price: float
    tax: Union[float, None] = None


@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Item = Body(embed=True)):
    results = {"item_id": item_id, "item": item}
    return results


# 通過get方式在URL路徑中接收請求參數(shù)
@app.get("/items/{item_id}")
async def read_root1(item_id: int = Path(..., gt=0)):
    return {"item_id": item_id}

# 雖然是通過post方式提交請求,但item_id仍然是在URL中通過?item_id進行請求
@app.post("/items")
async def read_root2(item_id: int = Query(..., ge=1)):
    return {"item_id": item_id}

# post方式提交請求,但item_id仍然是在URL中通過?item_id進行請求
@app.post("/items")
async def read_root2(
	item_id: int = Body(..., ge=1, embed=True),
	item_name: str = Body(None, max_length=20)):
    return {"item_id": item_id, "item_name": item_name}


8、typing類型注解

typing —— 類型注解支持 — Python 3.11.0 文檔

8.1 常用類型提示

前兩行小寫的不需要 import,后面三行都需要通過 typing 模塊 import

  • int,long,float: 整型,長整形,浮點型;
  • bool,str: 布爾型,字符串類型;
  • List, Tuple, Dict, Set:列表,元組,字典, 集合;
  • Iterable,Iterator:可迭代類型,迭代器類型;
  • Generator:生成器類型;
# 下面的函數(shù)接收與返回的都是字符串,注解方式如下:
def items(name: str) -> str:
    return "hello" + name

print(items("123"))

>>>hello123

FastAPI 基本使用(一)

8.2 Optional 可選類型

????????(聲明a :Optional[int] = None) ,參數(shù)除了給定的默認(rèn)值外還可以是None(作用是讓編譯器識別到該參數(shù)有一個類型提示,可以使指定類型,也可以是None,且參數(shù)是可選非必傳的)。注意 Optional[] 里面只能寫一個數(shù)據(jù)類型。即 Optional[X] 等價于 Union[X, None]

typing —— 類型注解支持 — Python 3.11.0 文檔

# 參數(shù)end是可選擇的參數(shù),有end就返回需求的,沒有end返回所有的
@app.get("/params")
async def read_param(start: int = 0, end: Optional[int] = None):
    if end:
        return data[start:end]
    return data[start::]

8.3 Union 聯(lián)合類型

# Union[int, None] 表示既可以是 int,也可以是 None。沒有順序的說法

python 3.6 及以上版本,需要導(dǎo)入typing中的Union
from typing import Union

class UserIn(BaseModel):
    username: str
    password: str
    email: EmailStr
    full_name: Union[int, None] = None


python 3.9 及以上版本 ,不需要導(dǎo)入typing中的Union
class UserIn(BaseModel):
    username: str
    password: str
    email: EmailStr
    full_name: int | None = None


8.4?typing List

  1. typing 模塊中導(dǎo)入 List,可以定義類型sellarea : List[str] = [];
  2. typing 的 List、Set、Tuple 都會指定里面參數(shù)的數(shù)據(jù)類型;
  3. FastAPI 會對聲明了數(shù)據(jù)類型的數(shù)據(jù)進行數(shù)據(jù)校驗,所以會針對序列里面的參數(shù)進行數(shù)據(jù)校驗;
  4. 如果校驗失敗,會報一個友好的錯誤提示;
  5. 使用時需要導(dǎo)入?from typing import List, Tuple;
from typing import Optional
 
import uvicorn
from fastapi import FastAPI, Body
from typing import List, Tuple
 
app = FastAPI()
 
 
@app.put("/items/{item_id}")
async def update_item(
        list_: List[int] = Body(...),
        tuple_: Tuple[int] = Body(...),
):
    results = {"list_": list_, "tuple_": tuple_}
    return results
 
 
if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8080)

9、請求示例展示在接口文檔中

使用Config 和 schema_extra 為Pydantic模型聲明一個簡單的示例

import uvicorn
from fastapi import FastAPI, Path, Query
from pydantic import BaseModel, Field
from typing import Union

class Items(BaseModel):
    name: str
    desc: Optional[str] = None
    price: float
    tax: Optional[float] = None
    
# 接口請求示例展現(xiàn)在接口文檔中
"""使用Config 和 schema_extra 為Pydantic模型聲明一個簡單的示例"""
    class Config:
        schema_extra = {
            "example": {
                "name": "書名",
                "price": 20,
                "decs": "描述信息",
                "tax": 0.5
            }
        }


@app.post("/items1")
async def retrun_item(item: Items):
    results = {"item": item}
    return results


"""
通過工廠函數(shù),增加example參數(shù)
注意:傳遞的額外參數(shù)不會添加任何驗證,只會添加注釋,用于文檔的目的
"""

class Item(BaseModel):
    name: str = Field(example="Foo")
    description: Union[str, None] = Field(default=None, example="A very nice Item")
    price: float = Field(example=35.4)
    tax: Union[float, None] = Field(default=None, example=3.2)


@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Item):
    results = {"item_id": item_id, "item": item}
    return results

if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8000)

FastAPI 基本使用(一)

?FastAPI 基本使用(一)

10 、Cookie,Header參數(shù)

  1. Header 是 Path, Query 和 Cookie 的兄弟類型。它也繼承自通用的 Param 類;
  2. 從fastapi導(dǎo)入 Query, Path, Header, 或其他時,實際上導(dǎo)入的是返回特定類型的函數(shù);
"""
header的必須有token且token必須是456,沒有返回?zé)o權(quán)限,
cookie必須有一個name,且等于123,否則返回認(rèn)證失敗
"""
from typing import Optional
from fastapi import Cookie, FastAPI,Header
app = FastAPI()
@app.get("/items/")
def read_items(name:  Optional[str] = Cookie(None),
               token: Optional[str] =  Header(None)):
    if token is None or token!='456':
        return '無權(quán)限'
    if name is None or name !="123":
        return  "認(rèn)證失敗"

11 、響應(yīng)模型 response_model

class UserIn(BaseModel):
    username: str
    password: str
    email: str
    full_name: Optional[str] = None

class Userout(BaseModel):
    username: str
    email: str
    full_name: Optional[str] = None

@app.post("/user/", response_model=Userout)
def create_user(user: UserIn):
    return user

12 、響應(yīng)狀態(tài)碼-使用 status_code 參數(shù)來聲明

https://fastapi.tiangolo.com/zh/tutorial/response-status-code/

  1. 在任意的路徑操作中使用 status_code 參數(shù)來聲明用于響應(yīng)的 HTTP 狀態(tài)碼
  2. status_code 參數(shù)接收一個表示 HTTP 狀態(tài)碼的數(shù)字
  3. @app.post("/items/",?status_code=201)

13 、Form表單數(shù)據(jù)

  1. 需預(yù)先安裝 pip install python-multipart;
  2. 使用時需要導(dǎo)入 from fastapi import FastAPI, Form;
  3. Form 是直接繼承自 Body 的類;
  4. 表單數(shù)據(jù)的「媒體類型」編碼一般為 application/x-www-form-urlencoded;
import uvicorn
from fastapi import FastAPI, Form
app = FastAPI()
@app.post("/login/",status_code=200)
def login(username: str = Form(...), password: str = Form(...)):
    if password == "123456":
        return {"username": username}
    return "密碼錯誤"
    
# 注冊用戶,username長度8-16位,password長度6-16位,符合需求返回對應(yīng)username
@app.post("/register", status_code=200)
async def register(username: str = Form(..., min_length=8, max_length=16, regex='^[a-zA-Z]'),
                   password: str = Form(..., min_length=8, max_length=16, regex='^[0-9]')):
    return {"username": username}


if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8000)

14 、上傳文件-File, UploadFile

  1. 需要預(yù)先安裝 pip install python-multipart;
  2. 使用時需要導(dǎo)入 fromfastapiimportFastAPI,File,UploadFile;
  3. 聲明文件體必須使用 File,否則,F(xiàn)astAPI 會把該參數(shù)當(dāng)作查詢參數(shù)或請求體(JSON)參數(shù);
  4. UploadFile 的屬性如下:
    1. filename:上傳文件名字符串(str);
    2. UploadFile 支持async 方法;
    3. file: SpooledTemporaryFile( file-like 對象)。其實就是 Python文件,可直接傳遞給其他預(yù)期 file-like 對象的函數(shù)或支持庫;
    4. content_type:內(nèi)容類型(MIME 類型 / 媒體類型)字符串(str);
  5. UploadFile 與 bytes 相比有更多優(yōu)勢:
    1. 使用 spooled 文件:存儲在內(nèi)存的文件超出最大上限時,F(xiàn)astAPI 會把文件存入磁盤;
    2. 暴露的 Python SpooledTemporaryFile 對象,可直接傳遞給其他預(yù)期「file-like」對象的庫;
    3. 自帶 file-like async 接口;
    4. 可獲取上傳文件的元數(shù)據(jù);
    5. 這種方式更適于處理圖像、視頻、二進制文件等大型文件,好處是不會占用所有內(nèi)存;
  6. UploadFile 直接繼承自 Starlette 的 UploadFile;
from fastapi import FastAPI, File, UploadFile

app = FastAPI()

@app.post("/files/")
def create(file: bytes = File(...)):
    return {"file_size": len(file)}

@app.post("/uploadfile/")
def upload_file(file: UploadFile = File(...)):
    return {"filename": file.filename}

15 、處理錯誤-HTTPException

  1. 使用時需要導(dǎo)入 from fastapi import FastAPI, HTTPException;
  2. 觸發(fā) HTTPException 時,可以用參數(shù) detail 傳遞任何能轉(zhuǎn)換為 JSON 的值,不僅限于str;
from fastapi import FastAPI, HTTPException
app = FastAPI()
items = {"test": "淺說測試開發(fā)"}
@app.get("/items/{item_id}")
def read_item(item_id: str):
    if item_id not in items:
        raise HTTPException(status_code=404, detail="Item not found")
    return {"item": items[item_id]}

16、jsonable_encoder() 函數(shù)

https://fastapi.tiangolo.com/zh/tutorial/encoder/#__tabbed_1_2文章來源地址http://www.zghlxwxcb.cn/news/detail-476749.html

  1. FastAPI 內(nèi)部用來轉(zhuǎn)換數(shù)據(jù)的;
  2. 它接收一個對象,比如Pydantic模型,并會返回一個JSON兼容的版本;
  3. 使用時需要導(dǎo)入 from fastapi.encoders import jsonable_encoder;

17 、依賴注入-Depends

  1. from fastapi import Depends, FastAPI;
  2. 不帶括號時,調(diào)用的是這個函數(shù)本身 ,是整個函數(shù)體,是一個函數(shù)對象,不須等該函數(shù)執(zhí)行完成;
  3. 帶括號(參數(shù)或者無參),調(diào)用的是函數(shù)的執(zhí)行結(jié)果,須等該函數(shù)執(zhí)行完成的結(jié)果;
  4. 多次使用同一個依賴項:
    1. 如果在同一個路徑操作 多次聲明了同一個依賴項,例如,多個依賴項共用一個子依賴項,F(xiàn)astAPI 在處理同一請求時,只調(diào)用一次該子依賴項;
    2. FastAPI 不會為同一個請求多次調(diào)用同一個依賴項,而是把依賴項的返回值進行「緩存」,并把它傳遞給同一請求中所有需要使用該返回值的「依賴項」;
from fastapi import Depends

# 定義依賴項函數(shù)
def com_methods(q: Optional[str] = None, a: int = 0, b: int = 10):
    return {"q": q, "a": a, "b": b}

@app.get("/com_item1")
def com_item1(item1: dict = Depends(com_methods)):
    return item1

@app.post("/com_item2")
def com_item2(item2: dict = Depends(com_methods)):
    return item2


"""
class CommonQueryParams:

類實現(xiàn)依賴注入2中寫法:
1.commons: CommonQueryParams = Depends(CommonQueryParams)
2.commons: CommonQueryParams = Depends()
"""

# 全局都需要校驗token

from fastapi import  FastAPI,Header, HTTPException,Depends

def verify_token(token: str = Header(...)):
    if token!="asdfghjkl":
        raise HTTPException(status_code=400, detail="Token header invalid")
app = FastAPI(dependencies=[Depends(verify_token)])

到了這里,關(guān)于FastAPI 基本使用(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • FastAPI 庫(Python 的 Web 框架)基本使用指南(一)

    參考文檔: 中文文檔 輕松上手Python的Web神器:FastAPI教程 FastAPI 是一個基于 Python 的現(xiàn)代 Web 框架,它具有快速構(gòu)建高性能 API 的特點。 FastAPI 關(guān)鍵特性: 快速:可與 NodeJS 和 Go 并肩的極高性能(歸功于 Starlette 和 Pydantic)。最快的 Python web 框架之一。 高效編碼:提高功能開發(fā)

    2024年02月04日
    瀏覽(61)
  • 2-Linux  目錄介紹及基本指令和操作命令

    2-Linux 目錄介紹及基本指令和操作命令

    一、目錄介紹 /:表示的是根的意思 /bin:(binary)存放的是一些二進制文件,但是在Linux中二進制文件是可以被執(zhí)行的。這個目錄中的命令文件是給普通用戶使用(非超級管理員用戶)。 /etc:Linux下所有的配置文件都會存放到etc目錄。 /home:是所有非root用戶家目錄的一個集

    2024年02月08日
    瀏覽(51)
  • 探索 Linux vim/vi 編輯器:介紹、模式以及基本操作演示

    探索 Linux vim/vi 編輯器:介紹、模式以及基本操作演示

    ??作者:insist-- ??個人主頁: insist-- 的個人主頁 理想主義的花,最終會盛開在浪漫主義的土壤里,我們的熱情永遠(yuǎn)不會熄滅,在現(xiàn)實平凡中,我們終將上岸,陽光萬里 ??歡迎點贊??收藏??評論?? 前言 本文將介紹vim / vi編輯器是什么并詳細(xì)講解它的三種工作模式以及基

    2024年02月05日
    瀏覽(104)
  • 后端“fastapi”+前端“vue3+ts+ElementPlus”上傳文件到uploads目錄

    后端“fastapi”+前端“vue3+ts+ElementPlus”上傳文件到uploads目錄

    確保已安裝好python3和fastapi mail.py 運行fastapi服務(wù)器 使用瀏覽器訪問?http://127.0.0.1:8000/http://127.0.0.1:8000/docs 確保已安裝node.js和yarn 使用vite初始化前端目錄 ?安裝element-plus main.ts中導(dǎo)入element-plus ?修改vite.config.ts配置“CORS 跨域” 修改App.vue 運行 使用瀏覽器訪問?http://127.0.0.1:70

    2024年02月22日
    瀏覽(32)
  • vue3 + fastapi 實現(xiàn)選擇目錄所有文件自定義上傳到服務(wù)器

    vue3 + fastapi 實現(xiàn)選擇目錄所有文件自定義上傳到服務(wù)器

    大家好,我是yma16,本文分享關(guān)于vue3 + fastapi 實現(xiàn)選擇目錄文件上傳到服務(wù)器指定位置。 vue3系列相關(guān)文章: 前端vue2、vue3去掉url路由“ # ”號——nginx配置 csdn新星計劃vue3+ts+antd賽道——利用inscode搭建vue3(ts)+antd前端模板 認(rèn)識vite_vue3 初始化項目到打包 python_selenuim獲取csdn新星

    2024年02月08日
    瀏覽(18)
  • Vue基礎(chǔ)入門(2)- Vue的生命周期、Vue的工程化開發(fā)和腳手架、Vue項目目錄介紹和運行流程

    Vue基礎(chǔ)入門(2)- Vue的生命周期、Vue的工程化開發(fā)和腳手架、Vue項目目錄介紹和運行流程

    Vue生命周期:就是一個Vue實例從 創(chuàng)建 到 銷毀 的整個過程。 生命周期四個階段: ① 創(chuàng)建 ② 掛載 ③ 更新 ④ 銷毀 1.創(chuàng)建階段:創(chuàng)建響應(yīng)式數(shù)據(jù) 2.掛載階段:渲染模板 3.更新階段:修改數(shù)據(jù),更新視圖 watch 是監(jiān)聽的數(shù)據(jù)修改就觸發(fā), updated 是整個組件的dom更新才觸發(fā) 4.銷毀

    2024年03月10日
    瀏覽(58)
  • 開發(fā)API? FastAPI有效處理長時間運行任務(wù)的策略!

    快速且高效地構(gòu)建API是現(xiàn)代軟件開發(fā)的一個基礎(chǔ)方面。然而,由于數(shù)據(jù)處理、第三方服務(wù)調(diào)用或復(fù)雜計算等原因,經(jīng)常會遇到執(zhí)行時間較長的API端點。面對這樣的情況,確保這些長時間運行的任務(wù)不會降低用戶體驗或系統(tǒng)性能至關(guān)重要。本博客文章旨在指導(dǎo)您如何在FastAPI中管

    2024年02月10日
    瀏覽(21)
  • 提示3D標(biāo)題編輯器仍在運行怎么解決,以及3D標(biāo)題編輯器怎么使用

    提示3D標(biāo)題編輯器仍在運行怎么解決,以及3D標(biāo)題編輯器怎么使用

    在進行視頻剪輯時,尤其是剪輯一些帶有文字的開場視頻,一般都會使用具有立體效果的3D標(biāo)題,這樣制作出來的視頻效果不僅好看,還非常的炫酷,但是對于一些剛剛開始接觸視頻剪輯的小伙伴來說,可能對3D標(biāo)題還不是很了解,所以下面本文就給大家具體講解一下,提示

    2024年02月05日
    瀏覽(29)
  • SELinux、SELinux運行模式、破解Linux系統(tǒng)密碼、firewalld防火墻介紹、構(gòu)建基本FTP服務(wù)、systemd管理服務(wù)、設(shè)置運行模式

    SELinux、SELinux運行模式、破解Linux系統(tǒng)密碼、firewalld防火墻介紹、構(gòu)建基本FTP服務(wù)、systemd管理服務(wù)、設(shè)置運行模式

    作用:負(fù)責(zé)域名解析的服務(wù)器,將域名解析為IP地址 /etc/resolv.conf:指定DNS服務(wù)器地址配置文件 ip命令(Linux最基礎(chǔ)的命令) 1.查看IP地址 2.臨時添加IP地址 3.刪除臨時IP地址 ping 命令,測網(wǎng)絡(luò)連接 -c 指定ping包的個數(shù) ?常見的日志文件 /var/log/messages 記錄內(nèi)核消息、各種服務(wù)的公

    2024年01月18日
    瀏覽(48)
  • 【Linux】頂級編輯器Vim的基本使用及配置

    【Linux】頂級編輯器Vim的基本使用及配置

    ??作者主頁:@安 度 因 ??學(xué)習(xí)社區(qū):StackFrame ??專欄鏈接:Linux

    2024年02月03日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包