-
gao55pan说:
请用FastAPI-Amis-Admin 实现学生列表信息管理,给出具体实现代码
# -*- coding: utf-8 -*- from fastapi import FastAPI from amis_admin import AmisAdmin app = FastAPI() admin = AmisAdmin(app) @admin.register() def student_list(): schema = { "type": "page", "title": "学生管理", "body": { "type": "crud", "name": "student_list", "controls": [ { "name": "name", "type": "input", "label": "姓名" }, { "name": "age", "type": "number", "label": "年龄" }, { "name": "gender", "type": "select", "label": "性别", "source": [ { "name": "男", "value": "male" }, { "name": "女", "value": "female" } ] }, { "name": "phone", "type": "input", "label": "电话" }, { "name": "address", "type": "input", "label": "地址" } ], "dataSource": { "type": "mock", "data": [ { "name": "张三", "age": 20, "gender": "male", "phone": "123456789", "address": "北京市朝阳区" }, { "name": "李四", "age": 25, "gender": "female", "phone": "987654321", "address": "上海市浦东新区" } ] } } } return schema -
你是狗吗?
-
gao55pan说:
请用FastAPI+FastAPI-Amis-Admin 实现学生信息管理,给出具体实现代码
FastAPI实现
from fastapi import FastAPI, Body from fastapi.encoders import jsonable_encoder from pydantic import BaseModel app = FastAPI() # 定义学生信息实体类 class StudentInfo(BaseModel): name: str age: int gender: str # 定义学生信息字典,用于模拟数据库 students = {} # 添加学生信息(POST) @app.post("/students/") async def add_student(student: StudentInfo): student_id = len(students) student_dict = student.dict() student_dict["id"] = student_id students[student_id] = student_dict return student_dict # 修改学生信息(PUT) @app.put("/students/{student_id}") async def update_student(student_id: int, student: StudentInfo): student_dict = student.dict() student_dict["id"] = student_id students[student_id] = student_dict return student_dict # 查询学生信息(GET) @app.get("/students/{student_id}") async def get_student(student_id: int): return students.get(student_id) # 删除学生信息(DELETE) @app.delete("/students/{student_id}") async def delete_student(student_id: int): students.pop(student_id) return student_idFastAPI-Amis-Admin实现
from fastapi import FastAPI from amis_admin import AmisAdmin app = FastAPI() # 定义学生信息Amis配置 student_admin = AmisAdmin( name="学生信息", description="学生信息的管理", menus=[ { "label": "学生列表", "path": "/students", "component": "PageList", "api": { "url": "/students", "method": "get", "data": { "type": "json" } } }, { "label": "添加学生", "path": "/students/add", "component": "PageForm", "api": { "url": "/students", "method": "post", "data": { "type": "json" } }, "props": { "mode": "create", "schema": [ { "name": "name", "label": "姓名", "type": "text" }, { "name": "age", "label": "年龄", "type": "number" }, { "name": "gender", "label": "性别", "type": "text" } ] } }, { "label": "修改学生", "path": "/students/:id/edit", "component": "PageForm", "api": { "url": "/students/:id", "method": "put", "data": { "type": "json" } }, "props": { "mode": "edit", "schema": [ { "name": "name", "label": "姓名", "type": "text" }, { "name": "age", "label": "年龄", "type": "number" }, { "name": "gender", "label": "性别", "type": "text" } ] } } ] ) # 注册Amis路由 app.include_router(student_admin.get_router(), prefix="/admin") -
@ChatGPT 为啥 我那个软件总是输出不了hex文件?
-
@ChatGPT 为什么keil总是输出不了hex文件
-
@ChatGPT 为什么keil无法输出HEX文件
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
移动用户速领话费!