V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
djangovcps
V2EX  ›  Python

fastapi 大家都用什么脚手架,我总是想把 fastapi 改成 Django 风格

  •  
  •   djangovcps · 20 天前 · 2818 次点击
    • 用了 fastapi 还行用 django 风格,有点魔怔了
    • 用的 sqlalchemy 仿了下 django 的 User.objects.xxx 以及 await User.objects.aget
    • 路由注册使用视图类,添加 批量更新批量删除,详情,列表查询等路由,不走装饰器
    • 登录校验也通过类变量声明的形式 method_decorators = [login_required, ] img img img img img img
    第 1 条附言  ·  20 天前

    @mylifcc sqlalchemy 还真是,

    • 对于异步 async_session
    """
    query = select(User) 或者  select(User.username)
    result = await async_session.execute(query)
    result 用 scalar() 还是scalars() 
    还是 scalar().first() 
    还是 scalar().all() 
    还是直接 result.first() result.all()
    要根据  User User.username 使用不同的方式获取结果,我只能说,很幽默
    """
    
    
    21 条回复    2024-06-05 12:03:01 +08:00
    hahahasnoopy
        1
    hahahasnoopy  
       20 天前   ❤️ 8
    质疑 django ,理解 django ,成为 django ,干脆直接用 django 算了
    djangovcps
        2
    djangovcps  
    OP
       20 天前
    @hahahasnoopy 还真是
    mylifcc
        3
    mylifcc  
       20 天前
    fastpi orm 让我想死
    Goooooos
        4
    Goooooos  
       20 天前
    习惯就好,我还用 tornado 呢
    NCZkevin
        5
    NCZkevin  
       20 天前
    我也纠结过这个,看了 github 上大家的实现,国外比较流行用工厂模式,国内一般就 flask 那套
    KgM4gLtF0shViDH3
        6
    KgM4gLtF0shViDH3  
       20 天前
    因为 django 用起来确实爽,而且符合面向对象。就是性能不太好。
    frostming
        7
    frostming  
       20 天前   ❤️ 1
    喜欢 Django ORM 试试 Tortoise? https://tortoise.github.io/
    xd314697475
        8
    xd314697475  
       20 天前
    @mylifcc 尤其是 sqlmodel
    crackidz
        9
    crackidz  
       19 天前
    @frostming 看到这个我就想到 asyncmy 有个很隐蔽的并发 bug ,小概率触发.... https://github.com/long2ice/asyncmy/issues/89 看了一下代码上下文也没什么头绪...
    supergeek1
        10
    supergeek1  
       19 天前
    https://github.com/fastapi-practices/fastapi_best_architecture
    参考下这个项目吧,写的很规范
    coolair
        11
    coolair  
       19 天前
    说实话,我用过了几乎所有的 Python Web 框架,最后还是用回 Django 了……
    dayeye2006199
        12
    dayeye2006199  
       19 天前 via Android   ❤️ 1
    我的理解是,所有 python web 框架在复杂度上来之后,都会和 Django 越长越像
    gray0
        13
    gray0  
       19 天前
    rukeypei
        14
    rukeypei  
       19 天前
    折腾工具不赚钱.
    encro
        15
    encro  
       19 天前
    django 是经典之作。有几点其他框架很难替代。

    它:
    1 ,数据优先(先写 model ,自动迁移)
    2 ,应用分离(高度解耦和复用)
    3 ,配置式生成后台


    有了他,一般网站你真可以只关心业务和核心的数据了。
    mywaiting
        16
    mywaiting  
       19 天前
    其他的 Python Web 框架只能中午用,因为你早晚都得回到 Django 的怀抱

    如果有人非要杠一下,我就不用! flask/fastapi/tornado 用得可溜了!

    那么恭喜你,你肯定要重新发明一遍 Django 项目复杂度上来后是毫无疑问的
    ryanking8215
        17
    ryanking8215  
       19 天前
    那你肯定会喜欢 Django ninja
    LazypersonJKing
        18
    LazypersonJKing  
       19 天前
    目前使用 tortoise-orm 熟悉的 django-orm 回来了。自己个人项目玩,目前感觉还行
    ayang23
        19
    ayang23  
       19 天前
    直接用 ninja
    ddvv
        20
    ddvv  
       19 天前
    我从 fastapi 转 go 了
    volvo007
        21
    volvo007  
       13 天前 via iPhone
    ninja 现在有啥大变动吗,有没有啥坑了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2935 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:09 · PVG 21:09 · LAX 06:09 · JFK 09:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.