2016-08-28 15 views
2

我試圖運行Gunicorn的燒瓶應用程序。當我運行gunicorn app:index時,出現錯誤TypeError: index() takes 0 positional arguments but 2 were given。我見過的例子都沒有顯示index需要兩個參數。這個錯誤是什麼意思?如何與Gunicorn運行Flask?Gunicorn運行燒瓶引發TypeError:index()需要0個位置參數,但給出了2個

from flask import Flask 

app = Flask(__name__) 

@app.route("/") 
def index(): 
    return 'Hello, World!' 
gunicorn app:index 
respiter = self.wsgi(environ, resp.start_response) 
TypeError: index() takes 0 positional arguments but 2 were given 

我改變index取兩個參數,卻得到了不同的錯誤。

@app.route("/") 
def index(arg1, arg2): 
    return 'Hello, World!' 
/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' 

回答

2

你必須燒瓶實例傳遞給gunicorn,不喜歡你index做了一個函數名。因此,如果您的應用另存爲app.py,那麼您必須按以下方式運行gunicorn

$ gunicorn --bind 127.0.0.1:8000 app:app 
相關問題