Skip to content
Myr

Clarified language related to avoiding circular imports.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Drew Vogel · committed by Armin Ronacher · parent 235369f · Browse files · 1 file+4 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

1 file+4 added−4 removed

  • other:+4 added−4 removed

1 file+4 added−4 removed

modified:docs/patterns/packages.rst+4 added-4 removed
54 unmodified lines
55 `__init__.py` file. That way each module can import it safely and the56 `__name__` variable will resolve to the correct package.572. all the view functions (the ones with a :meth:`~flask.Flask.route`58 decorator on top) have to be imported when in the `__init__.py` file.59 Not the object itself, but the module it is in. Do the importing at60 the *bottom* of the file.59 Not the object itself, but the module it is in. Import the view module60 *after the application object is created*.6162Here's an example `__init__.py`::6364 from flask import Flask
92 unmodified lines
157Do the same with the `frontend.py` and then make sure to register the158modules in the application (`__init__.py`) like this::159160 from flask import Flask161 app = Flask(__name__)162163 from yourapplication.views.admin import admin164 from yourapplication.views.frontend import frontend163164 app = Flask(__name__)165 app.register_module(admin, url_prefix='/admin')166 app.register_module(frontend)167168We register the modules with the app so that it can add them to the
121 unmodified lines