nul*_*ter 5 python flask gunicorn
我正在尝试用Gunicorn运行Flask应用程序.当我跑gunicorn app:index,我得到错误TypeError: index() takes 0 positional arguments but 2 were given.我见过的所有例子都没有显示index需要两个参数.这个错误是什么意思?如何使用Gunicorn运行Flask?
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return 'Hello, World!'
Run Code Online (Sandbox Code Playgroud)
gunicorn app:index
Run Code Online (Sandbox Code Playgroud)
respiter = self.wsgi(environ, resp.start_response)
TypeError: index() takes 0 positional arguments but 2 were given
Run Code Online (Sandbox Code Playgroud)
我改变index了两个参数,但得到了一个不同的错误.
@app.route("/")
def index(arg1, arg2):
return 'Hello, World!'
Run Code Online (Sandbox Code Playgroud)
/python3.4/site-packages/flask/templating.py, line 132, in render_template
ctx.app.update_template_context(context)
AttributeError: 'NoneType' object has no attribute 'app'
Run Code Online (Sandbox Code Playgroud)
您必须将Flask实例传递给gunicorn,而不是像您一样传递函数名称index.因此,如果您的应用保存为app.py,则必须gunicorn按以下方式运行:
$ gunicorn --bind 127.0.0.1:8000 app:app
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2667 次 |
| 最近记录: |