[Flask] Deploying with mod_wsgi with factory function in __init__.py

Emlyn Price emlyn.je.price at gmail.com
Fri Jan 4 13:40:19 EST 2019


Hi,

I have been writing my first program using flask and ran into some
confusion when writing the my_application.wsgi file. I followed the
tutorial application structure, using a create_app() function in a file
called __init__.py. I installed the project in a virtualenv.

The flask docs say that for most apps the following file should be
sufficient: `from yourapplication import app as application`. When I tried
to use a file like this I get `TypeError: 'module' object not callable` in
the apache logs.

After some searching I found that the correct way to import an app like
that is:

```
from app import create_app
application = create_app()
```

This is the first time I have written a python project which can be
installed in this way. I would like to know if this is the expected way to
have to import a project written with a factory function in __init__.py?

If so, I think it would be useful to have a comment stating so in the docs.
I am happy to create a pull request if so.

I am using:
python 3.5.3
flask 1.0.2
mod_wsgi 4.5.11-1, installed from raspbian stretch repositories
Raspbian Stretch


Thanks,
Emlyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20190104/2dd18208/attachment.html>


More information about the Flask mailing list