fastpi简单crud
Project description
fastapi-admin
项目默认会安装
- fastapi_pagination
- fastapi
- tortoise-orm
目前只支持pydantic-v2
简单示例
main.py
from fastapi import FastAPI,Depends
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',)),
# 除了read接口,其他接口都需要登录
# dependencies=[Depends(get_current_user)],
# depends_read=False
)
app = FastAPI()
app.include_router(user, prefix='/user', tags=['用户管理'])
@app.get("/")
async def root():
return {"message": "Hello World"}
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
File details
Details for the file fastapi_tortoise_crud-0.2.7.tar.gz
.
File metadata
- Download URL: fastapi_tortoise_crud-0.2.7.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.2 CPython/3.12.3 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bfb584614a4610f698f6c979bb66cf5a7cfede4c5477523a198ae8d25ee2bb6 |
|
MD5 | 4570336df692a8f6961447f8e5ece6ce |
|
BLAKE2b-256 | 30e2aeaab063b23632f48f8c79ec88ab958f4be1c7c4721b441a2f0fbf7bb4a0 |
File details
Details for the file fastapi_tortoise_crud-0.2.7-py3-none-any.whl
.
File metadata
- Download URL: fastapi_tortoise_crud-0.2.7-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.2 CPython/3.12.3 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eedf972b84eacc2652ceaadb2ba08759f4b92f90694326265b74dada4ef7f1a6 |
|
MD5 | dc243fa87d92379c6465140a7d296dc3 |
|
BLAKE2b-256 | bb68106db30f64750e31893bef52b17fc21cfcdf6ed942db685fcd4e234d0049 |