方式一
1.运行main1.py代码
2.在终端输入 uvicorn main1:app --reload
3.在浏览器网页输入对应网址
main1.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
方式二
1.运行main2.py代码
2.在浏览器网页输入对应网址
main2.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def main():
return {"messages": "helloworld, FastAPI"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)