首页 > 其他分享 >[FastAPI-04]查询参数-分页

[FastAPI-04]查询参数-分页

时间:2023-03-22 09:23:13浏览次数:39  
标签:分页 04 title FastAPI page books id size

from fastapi import FastAPI

BOOKS = [
    {"id": 1, "title": "book1"},
    {"id": 2, "title": "book2"},
    {"id": 3, "title": "book3"},
    {"id": 4, "title": "book4"},
    {"id": 5, "title": "book5"},
    {"id": 6, "title": "book6"},
    {"id": 7, "title": "book7"},
    {"id": 8, "title": "book8"}
]

app = FastAPI()


# 查询参数
# /books?page=1&size=10 第1页 第10行
# ?后面为查询的参数对多个参数使用&连接
@app.get("/books/")
def books(page: int, size: int):
    # 列表页分页效果 每页显示size个数量
    return BOOKS[(page - 1) * size:page * size]

http://10.105.212.1:8000/books/?page=2&size=3

[
  {
    "id": 4,
    "title": "book4"
  },
  {
    "id": 5,
    "title": "book5"
  },
  {
    "id": 6,
    "title": "book6"
  }
]

标签:分页,04,title,FastAPI,page,books,id,size
From: https://www.cnblogs.com/leoshi/p/17242361.html

相关文章

  • Ubuntu18.04设置bond0
    Ubuntu18.04设置bond6有两种方法,一是在安装系统的设置网卡聚合,二是修改/etc/netplan/*.yaml这个配置文件。一,安装系统时设置bond61,正常进入Ubuntu18.04的安装界面2,选择键......
  • B04完全平方数
    publicclassA04完全平方数{//一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?publicstaticvoidmain(String[]args){inti......
  • 学习记录:day04笔记
    一、for循环语句循环:就是一种让代码反复执行的方式,从而达到想要的效果for循环一般会使用一个变量来引导循环的进行,这一变量叫做该循环的循环变量iindexfor循环的变......
  • CS/INFO 5304数据预处理
    CS/INFO5304Assignment1:DataPreparationCredit:94pointsGrade:20%offinalgradeSubmission:Filesthatneedtobesubmittedforarelistedattheendofe......
  • markdown分页导出pdf
    问题markdown不能分页导出pdf不美观方案在需要分页之处插入以下html代码,在导出pdf时生效<divSTYLE="page-break-after:always;"></div>......
  • how to uninstall apps in Ubuntu 22.04(Jammy)
    todayIwannauninstallappsinsideUbuntubutfailedviaStore. soIneedtounstallthemmanullyasbelow.$aptlist--installed|grep-iaisleriotW......
  • fastapi多线程非阻塞启动
    1问题描述我在run.py文件下的主函数如下所示:importuvicornfromfastapiimportFastAPIapp=FastAPI(title="chatglm",description="开源版的chatglm接......
  • Day04 - 判断数据类型的方式有哪些?| 面试365
    知识讲解​​JavaScript​​判断数据类型的方式共有四种typeofinstanceofconstructorObject.prototype.toStringtypeof​​typeof​​操作符返回一个字符串,表示操作值的......
  • nginx反向代理出现404
    #nginx主要还是配置nginx.conf如果你配置的nginx反向代理有问题,导致无法加载css,js等内容那么,你可以先把你添加的内容先干掉,加上如下所示内容,或者参考如下胚子信息upstream......
  • 04--Qt信号与信号槽
    直接上图优点:松散耦合,信号发出端和接收端可以毫无关联,如果要关联,就用connect函数connect函数使用常用的一般模式connect(sender,signal,receiver,slot);参数:1、信......