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
.
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:
if __name__ == "__main__": app.run()
This allows us to execute the module file with the Python interpreter directly, as follows:
$ python app.py * Running on http://localhost...