[FastAPI-01]HelloWorld

1. 环境搭建

https://www.cnblogs.com/leoshi/p/15567193.html

/root/.pyenv/versions/3.9.14/bin/python3.9 -m pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com --upgrade pip
pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com fastapi
pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com uvicorn
pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com python-multipart

2. HelloWorld

# _*_ coding: UTF-8 _*_
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def main():
    return {"message":"Helloworld , FastAPI"}

if __name__ == '__main__':
    import uvicorn
    uvicorn.run("main:app",host='127.0.0.1',port=8000)

3. 启动程序

uvicorn main:app --reload --host 0.0.0.0 --port 8000

END

posted @ 2022-11-11 19:16  LeoShi2020  阅读(56)  评论(0)    收藏  举报