FastAPI的两种启动方式
来个简单的Hello world 例子
import uvicorn from fastapi import FastAPI app = FastAPI() @app.get('/') async def root(): return {"msg": "Hello World"} if __name__ == '__main__': uvicorn.run('test02:app')
第一种:通过uvicorn.run()启动,其中test02为当前py文件,app为FastAPI的实例对象,这样启动默认为http://127.0.0.1:8000,当然也可以更改host和port
第二种:通过命令uvicorn test02:app --reload 其中--reload :可以自动重启
本文来自博客园,作者:手可摘星辰/*,转载请注明原文链接:https://www.cnblogs.com/u-damowang1/p/16016130.html