Skip to main content

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='游客')

路由

img.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-tortoise-crud-0.1.16.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_tortoise_crud-0.1.16-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

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

Hashes for fastapi-tortoise-crud-0.1.16.tar.gz
Algorithm Hash digest
SHA256 1fce72758d745f5aace18f148857c8cea8d2f300ebc04b8ce5a8896eeea0f172
MD5 bbfc5dfb182702cb341ddcd98ccb77db
BLAKE2b-256 3dea5384f0b5a88d5f650187dcd3a5878b2eb80333ee54f6e2cfe5e0a4075f2e

See more details on using hashes here.

File details

Details for the file fastapi_tortoise_crud-0.1.16-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_tortoise_crud-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 35b63f126944b03e7c480119263bb60edf03b132186ca0d5d3ac514245ce21e8
MD5 861e8f2a8cf90685d2ca52ea4fb92101
BLAKE2b-256 94f7791fb4bcadbc75e700d692f2759dae9a156e4b496c56bacf02d677081a02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page