Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

初尝FastAPI #5

Open
bonfy opened this issue Nov 17, 2020 · 1 comment
Open

初尝FastAPI #5

bonfy opened this issue Nov 17, 2020 · 1 comment

Comments

@bonfy
Copy link
Owner

bonfy commented Nov 17, 2020

FastAPI 可谓说目前Python Web Framework 中的当红炸子鸡,一直只闻其名,没有尝试过,今天抽空也尝试一把。

主页

安装

$ pip3 install fastapi
$ pip3 install uvicorn # run as server

$ uvicorn main:app --reload

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [28720]
INFO:     Started server process [28722]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

参考资料

@bonfy
Copy link
Owner Author

bonfy commented Nov 17, 2020

main.py

# coding: utf-8

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def home():
    return {'status': 'ok'}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
$ uvicorn main:app --reload --host 0.0.0.0 --port 8000

Gunicorn

$ pip3 install  gunicorn

$ gunicorn -w 4 -b 0.0.0.0:5000  manage:app -D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant