[Flask] Application structure best practice?

Tom Vaughan thomas.david.vaughan at gmail.com
Thu Apr 13 15:15:35 EDT 2017


Hey Skip,

Please see https://gitlab.com/tvaughan/docker-flask-starterkit

The app is created in
https://gitlab.com/tvaughan/docker-flask-starterkit/blob/master/app/starterkit/app.py#L39.
This approach allows for different environments, like development and
production (https://gitlab.com/tvaughan/docker-flask-starterkit/tree/master/app/starterkit/settings),
via an environment variable
(https://gitlab.com/tvaughan/docker-flask-starterkit/blob/master/Makefile#L23
and https://gitlab.com/tvaughan/docker-flask-starterkit/blob/master/coreos/etc/systemd/system/app.service#L12)
or manually (https://gitlab.com/tvaughan/docker-flask-starterkit/blob/master/app/starterkit/tests/helpers.py#L11).
uWSGI then creates the app via
https://gitlab.com/tvaughan/docker-flask-starterkit/blob/master/app/uwsgi.ini#L4.

I don't claim this constitutes "best practices." This is just what
I've done to solve this problem.

Best,
-Tom



On Thu, Apr 13, 2017 at 3:23 PM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> I asked a colleague about some mildly confusing (to me) usage of the name
> "app". He got it from this tutorial:
>
> https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
>
> Not quite halfway through the blog, he has the reader create an app
> directory, then an __init__.py file in it containing these lines:
>
> from flask import Flask
>
> app = Flask(__name__)
> from app import views
>
>
> The author then spends a couple short paragraphs explaining the double-duty
> done by the name "app" and the atypical import at the end of the module
> (personally, not where I look first for import statements). This seems odd
> to me, but if that's the common idiom, I'm happy to go with it. The Flaskr
> tutorial has a bit different structure. The lack of an __init__.py file
> suggests that it's written using Python 3. I'm stuck with Python 2 for the
> foreseeable future, however. Do people use different schemes to setup their
> application structures? Is there a "best practice" for the application
> structure?
>
> Thx,
>
> Skip Montanaro
>
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>


More information about the Flask mailing list