Running Flask with Gunicorn raises TypeError: index() takes 0 positional arguments but 2 were given
<p>I'm trying to run a Flask app with Gunicorn.  When I run <code>gunicorn app:index</code>, I get the error <code>TypeError: index() takes 0 positional arguments but 2 were given</code>.  None of the examples I've seen show <code>index</code> needing two parameters.  What does this error mean?  How do I run Flask with Gunicorn?</p>

<pre><code>from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return 'Hello, World!'
</code></pre>



<pre><code>gunicorn app:index
</code></pre>



<pre><code>    respiter = self.wsgi(environ, resp.start_response)
TypeError: index() takes 0 positional arguments but 2 were given
</code></pre>

<p>I changed <code>index</code> to take two arguments, but got a different error.</p>

<pre><code>@app.route("/")
def index(arg1, arg2):
    return 'Hello, World!'
</code></pre>



<pre><code>  /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'
</code></pre>

<p>You have to pass a Flask instance to <code>gunicorn</code>, not a function name like you did with <code>index</code>. So if your app saved as <code>app.py</code>, then you have to run <code>gunicorn</code> as follows:</p>

<pre><code>$ gunicorn --bind 127.0.0.1:8000 app:app
</code></pre>

python flask gunicorn