From module to package
The simplest structural change that can be applied to a module-based Flask application is to transform it into a typical Python package, with special accommodation for the static and templates folders.
application └──application ├──__init__.py ├──static │ ├──app.js │ └──styles.css └──templates ├──index.html └──layout.html
Here, we created a top-level application package, moved the app.py
module along with the static
and template
folders inside it, and renamed it __init__.py
.
Note
The __init__.py
file is required for a folder to be considered a valid Python package.
One detail that should be handled at this point is the code that is used to run the development server. If you recall, the single-module application contained the following conditional statement...