From 3deae1bd48bf7dfad863afae4d368993fc9bafe1 Mon Sep 17 00:00:00 2001 From: Drew Vogel Date: Wed, 9 Mar 2011 12:31:39 -0600 Subject: [PATCH] Clarified language related to avoiding circular imports. Signed-off-by: Armin Ronacher --- docs/patterns/packages.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/patterns/packages.rst b/docs/patterns/packages.rst index a6c7cce0..e1b92c08 100644 --- a/docs/patterns/packages.rst +++ b/docs/patterns/packages.rst @@ -56,8 +56,8 @@ following quick checklist: `__name__` variable will resolve to the correct package. 2. all the view functions (the ones with a :meth:`~flask.Flask.route` decorator on top) have to be imported when in the `__init__.py` file. - Not the object itself, but the module it is in. Do the importing at - the *bottom* of the file. + Not the object itself, but the module it is in. Import the view module + *after the application object is created*. Here's an example `__init__.py`:: @@ -158,10 +158,10 @@ Do the same with the `frontend.py` and then make sure to register the modules in the application (`__init__.py`) like this:: from flask import Flask + app = Flask(__name__) + from yourapplication.views.admin import admin from yourapplication.views.frontend import frontend - - app = Flask(__name__) app.register_module(admin, url_prefix='/admin') app.register_module(frontend)