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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi-tortoise-crud-0.1.16.tar.gz.
File metadata
- Download URL: fastapi-tortoise-crud-0.1.16.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.4.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fce72758d745f5aace18f148857c8cea8d2f300ebc04b8ce5a8896eeea0f172
|
|
| MD5 |
bbfc5dfb182702cb341ddcd98ccb77db
|
|
| BLAKE2b-256 |
3dea5384f0b5a88d5f650187dcd3a5878b2eb80333ee54f6e2cfe5e0a4075f2e
|
File details
Details for the file fastapi_tortoise_crud-0.1.16-py3-none-any.whl.
File metadata
- Download URL: fastapi_tortoise_crud-0.1.16-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.4.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35b63f126944b03e7c480119263bb60edf03b132186ca0d5d3ac514245ce21e8
|
|
| MD5 |
861e8f2a8cf90685d2ca52ea4fb92101
|
|
| BLAKE2b-256 |
94f7791fb4bcadbc75e700d692f2759dae9a156e4b496c56bacf02d677081a02
|