37创客科创中心

 找回密码
 立即注册
查看: 2030|回复: 1

前端接口神器之 json-server 详细使用指南

[复制链接]

194

主题

324

帖子

2405

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2405
发表于 2023-5-18 22:01:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
ECT 快速开发框架1.0
快速上线小程序接口、app接口、api接口、web程序
  • 适合前端程序员、服务端小白,快速上手写服务端程序、大型项目
  • 采用thinkphp6.0 为核心 每个程序拥有独立的 Controller、Mysql
  • 全自动化生成路由、助手面板、行为日志分析、一键启调试模式、导出zip
  • 内置丰富中文函数 文档方便阅读 方便开发

回复

使用道具 举报

194

主题

324

帖子

2405

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2405
 楼主| 发表于 2023-5-18 22:03:12 | 显示全部楼层
使用 Pydantic orm_mode
现在,在Pydantic模型读取,Item并且User,添加一个内部Config类。

此类Config用于向 Pydantic 提供配置。

在Config类中,设置属性orm_mode = True。


from typing import List, Optional

from pydantic import BaseModel


class ItemBase(BaseModel):
    title: str
    description: Optional[str] = None


class ItemCreate(ItemBase):
    pass


class Item(ItemBase):
    id: int
    owner_id: int

    class Config:
        orm_mode = True


class UserBase(BaseModel):
    email: str


class UserCreate(UserBase):
    password: str


class User(UserBase):
    id: int
    is_active: bool
    items: List[Item] = []

    class Config:
        orm_mode = True
提示

请注意,它正在分配一个值=,例如:

orm_mode = True
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-13 07:55 , Processed in 0.214578 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表