Giter Site home page Giter Site logo

fastapi-skeleton's Issues

尊敬的作者,请教个问题

使用了您这个作品,在安装完整依赖后运行测试,发现以下错误,能否指点一二:
File "C:\Users\jeffr\Dev\Python\py-center\venv\Lib\site-packages\pydantic\main.py", line 292, in new
cls.signature = ClassAttribute('signature', generate_model_signature(cls.init, fields, config))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jeffr\Dev\Python\py-center\venv\Lib\site-packages\pydantic\utils.py", line 258, in generate_model_signature
merged_params[param_name] = Parameter(
^^^^^^^^^^
File "C:\Python311\Lib\inspect.py", line 2715, in init
raise ValueError('{!r} is not a valid parameter name'.format(name))
ValueError: 'not' is not a valid parameter name

路由定义问题

尊敬的作者,您好:
非常感谢您能分享与FastAPI相关的业务框架。这里我存在一个疑问点:由于您使用了peewee作为ORM,但该ORM并不是异步ORM。在定义路由时,您采用了异步定义路由函数:

@router.post("/token", response_model=Token, dependencies=[Depends(get_db)])
async def token(request_data: OAuth2PasswordRequest):
    """
    用户名+密码登录
    """
    grant = PasswordGrant(request_data)
    return grant.respond()

根据FastAPI内部特性,同步函数将采用线程池执行,异步函数将由事件循环负责执行。
因此我的疑问点是/token这个路由能并发吗?通过peewee执行操作时,会阻塞整个程序的运行吧?
针对内部存在同步阻塞IO的路由应该定义为同步路由。

关于不同环境间config切换问题的疑问

作者您好:

我基于main分支启动后,测试接口的时候发现数据库链接不上,修改了.env.example中的配置后,却无法生效。后来我定位到了数据库设置的代码段落:

class Settings(BaseSettings):
    """mysql db"""
    DB_HOST: str = '127.0.0.1'
    DB_PORT: int = 3306
    DB_DATABASE: str = 'fastapi'
    DB_USER: str = 'root'
    DB_PASSWORD: str = '123456'

    class Config:
        env_file = ".env"

发现env_file中的文件指向的是.env。
如果在项目开发中有dev,test,prod三个环境对于三个env_file :.env.dev,.env.test,.env.prod。如何能做到根据不同的环境读取不同的配置呢?
目前的代码似乎不支持启动入参的设置。
如果通过 python main.py --env_file .env.dev 这种入参的形式解决不同环境启动问题,那每一个Settings 下面的env_file都得做一遍替换,直觉上觉得不太合理。
作者有没有好的建议?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.