amisadmin / fastapi-amis-admin

FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.
http://docs.amis.work
Apache License 2.0
1.09k stars 161 forks source link

这确确实实是个好东西,但是教程还是有点问题,小白跟着写估计都跑不下来 #102

Open Brandon-lz opened 1 year ago

Brandon-lz commented 1 year ago

比如这段教程,创建表单的,非常棒的功能和设计,但是没有完整的import代码,很难找到对应的类

from fastapi_amis_admin.admin import admin
from fastapi_amis_admin.crud import BaseApiOut
from fastapi_amis_admin.models.fields import Field
from pydantic import BaseModel
from starlette.requests import Request

@site.register_admin
class UserLoginFormAdmin(admin.FormAdmin):
    page_schema = 'UserLoginForm'
    # 配置表单信息, 可省略
    form = Form(title='这是一个测试登录表单', submitText='登录')

    # 创建表单数据模型
    class schema(BaseModel):
        username: str = Field(..., title='用户名', min_length=3, max_length=30)
        password: str = Field(..., title='密码')

    # 处理表单提交数据
    async def handle(self, request: Request, data: BaseModel, **kwargs) -> BaseApiOut[Any]:
        if data.username == 'amisadmin' and data.password == 'amisadmin':
            return BaseApiOut(msg='登录成功!', data={'token': 'xxxxxx'})
        return BaseApiOut(status=-1, msg='用户名或密码错误!')

丢了一个Form类的引入,加入from fastapi_amis_admin.amis.components import Form 后成功运行。

虽然找找源码也能解决,但是我估计百分之七十的初学者都不会去看源码,这么好的项目千万不要沉啊。

EchoShoot commented 1 year ago

Woc,宝藏项目,别沉了!