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

Nicolas Le Manchet nicolas at lemanchet.fr
Fri Jan 4 16:18:30 EST 2019


Hi,

Short answer: yes, the behavior you see is expected.

All WSGI servers need an application (a callable that follows specific conventions) to work.

- Using Flask without application factory it's enough to just import the global application that already exists.
- Using Flask with application factory no global application exists so it is required to create an application using the factory so the WSGI server can access it.


On Fri, Jan 4, 2019, at 19:40, Emlyn Price wrote:
> 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
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask


-- 
Nicolas Le Manchet


More information about the Flask mailing list