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.14.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e691fcf20db911f18c52758b395f8f552bb0a3763ef1a79638d00462111d8eb8 |
|
MD5 | 44fd322ecedee96bbd41f4d383d6d7fd |
|
BLAKE2b-256 | d3c36a4886ea9563e5b9361471bafba18e6a71efb5053a80bce80aa918d80096 |
Close
Hashes for fastapi_tortoise_crud-0.1.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e710127681c6edeca38dd5d57762285ebc04841f3b466083f4f261a79452d224 |
|
MD5 | 876c8327ef906e65c28f714eaa6a52bb |
|
BLAKE2b-256 | 48fb11f6f7e59d2c0b46b0ffb5342489bd85deb7f8e2500e0659a2ad46c8bdce |