shearichard
shearichard

Reputation: 8372

Flask deployment using twistd

In the flask doco the following description is shown of deploying a flask app under twistd.

twistd web --wsgi myproject.app

I have a foo.py which looks like this

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

So I expected to be able to run that under twistd like this

twistd web --wsgi foo.app

but twistd doesn't like that (just spits out the help text).

What am I doing wrong ?

BTW in case it matters I'm running this in a virtualenv (in which I have installed both flask and twisted) and the current directory when I issue the twistd command contains foo.py .


EDIT: The version of twistd I am using is 18.7.0

I had failed to notice (until prompted to by Peter Gibson's comment ) that after the help text appears the message "No such WSGI application: 'foo.app'" appears.

Upvotes: 3

Views: 614

Answers (1)

Peter Gibson
Peter Gibson

Reputation: 19564

You need to add the current directory to the PYTHONPATH environment variable. Try

PYTHONPATH=. twistd web --wsgi foo.app

Or on Windows (untested)

set PYTHONPATH=.
twistd web --wsgi foo.app

Upvotes: 6

Related Questions