Forums

Running the flask tutorial on pythonanywhere

I want to run the flask tutorial on pythonanywhere, but I don't know how to configure wsgi to work with the app structure of the tutorial. Unlike most flask apps the tutorial doesn't create an app on the module level, but it creates the app in a function called create_app.

The flask tutorial has a simple deployment with waitress where you can call a function directly like this:

waitress-serve --call 'flaskr:create_app'

Unfortunately I know next to nothing about wsgi. Could somebody tell me, how I achieve the same with the configuration in pythonanywhere wsgi configuration file?

At the moment I get the following error message in the error.log:

2018-05-31 10:10:48,471: Error running WSGI application
2018-05-31 10:10:48,471: TypeError: 'NoneType' object is not iterable

What you need to do in the WSGI file is defines a variable called application that is a WSGI application object. A Flask app is (if you've set things up the normal way) that kind of object. So if you have a file that defines a function called create_app that returns the Flask app, you just need to call it in the WSGI file. Working from the code on this part of the Flask tutorial, that would look something like this (with the path adjusted appropriately):

path = '/home/killerwebdev/mysite'
if path not in sys.path:
    sys.path.append(path)

from flaskr import create_app
application = create_app()  # noqa

This worked, thanks.

Excellent, thanks for confirming!