kaxiluo / fastapi-skeleton Goto Github PK
View Code? Open in Web Editor NEWfastapi skeleton. framework integration orm jwt-auth loguru dotenv APScheduler...
fastapi skeleton. framework integration orm jwt-auth loguru dotenv APScheduler...
使用了您这个作品,在安装完整依赖后运行测试,发现以下错误,能否指点一二:
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
拿来开发api后台很不错,建议增加微信用户登陆认证功能。
类如:
{
"ret": 200,
"data": [data],
"msg": [message]
}
不知道提议是否科学,建议而已
尊敬的作者,您好:
非常感谢您能分享与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的路由应该定义为同步路由。
作者您好:
我基于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都得做一遍替换,直觉上觉得不太合理。
作者有没有好的建议?
class Settings(BaseSettings):
JWT_TTL: int = 60 * 24 * 8
JWT_SECRET_KEY: str = ""
JWT_ALGORITHM: str = 'HS256'
class Config:
env_file = ".env"
env_file_encoding = 'utf-8'
想了解一下,定义这个Config有什么作用?
大佬,用的什么版本的python3啊
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.