我有一个由诗歌构建的 fastapi 项目。我想在 pyproject.tom 中使用脚本部分运行应用程序,如下所示:
poetry run start
Run Code Online (Sandbox Code Playgroud)
该部分中的双引号内是什么?
[tool.poetry.scripts]
start = ""
Run Code Online (Sandbox Code Playgroud)
我尝试运行以下脚本。
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
def main():
print("Hello World")
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True, workers=2)
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
它停止应用程序并只显示这样的警告。
警告:您必须将应用程序作为导入字符串传递以启用“重新加载”或“工人”。