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.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e34e78b1956e12e74f5f060594c957b349b0b294c1b5ac5e992172a2bc373472 |
|
MD5 | 9399c64a7472e1e3eca34d9653f997dc |
|
BLAKE2b-256 | e4682b1ff6ca4baa3b15b58b68a9c28bc4a4786f3dc973d5751acf17be864348 |
Close
Hashes for fastapi_tortoise_crud-0.1.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 476361af6aefd62a32d6f444fe55e0db4182adb83272512eba412662e3d16d65 |
|
MD5 | 1411764cb70b6ccd1c9741492863b51c |
|
BLAKE2b-256 | a6e2e01f1fecdf052b411e646ec0ab1c79139cc5685f19d54763cc59e9a8dd7d |