fastpi简单crud
Project description
fastapi-admin
项目默认会安装
- fastapi_pagination
- fastapi
- tortoise-orm
目前只支持pydantic-v2
简单示例
main.py
from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise
from uvicorn import run
from models import User
from fastapi_tortoise_crud.crud import ModelCrud
user = ModelCrud(User,
schema_filters=User.schema_filters(include=('username',))
).register_crud()
app = FastAPI()
app.include_router(user, prefix='/user', tags=['用户管理'])
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
register_tortoise(
app,
db_url="sqlite://:memory:",
modules={"models": ["models"]},
generate_schemas=True,
add_exception_handlers=True,
)
if __name__ == '__main__':
run("main:app", port=2103, reload=True)
models.py
from fastapi_tortoise_crud.model import BaseModel
from tortoise import fields
class User(BaseModel):
username = fields.CharField(64)
password = fields.CharField(32)
nickname = fields.CharField(32, null=True, default='游客')
路由
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for fastapi-tortoise-crud-0.1.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fde4fff6774639fefbd889bd89b751ade9eb29c277a06b7f7b5b2f1b0f366bfe |
|
MD5 | fa7444c832ff5b71bab102b85f851c92 |
|
BLAKE2b-256 | 5bd11ba51d1fd5de1704c11a13bdf0fc076a09e8873c5892b236b855e3405dd8 |
Close
Hashes for fastapi_tortoise_crud-0.1.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01d706bb359ba0a1a361f850a7e3f73c9da8bcc148683093109a3ecc4b3a5952 |
|
MD5 | 12e29eee7ecdb49ac16e2df81c083926 |
|
BLAKE2b-256 | c964a8386cf554b1e70ff80316a4bbdb858f094248002b8a1394a228833a96b5 |