1. 环境搭建
/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
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(app,host='127.0.0.1',port=8000)