This is a template for a Flask project using a modular architecture. This project facilitates the creation of a Flask
project with a modular architecture, allowing the creation of new modules by extending a class and adding it to a set.
This template has some flask extension installed, such as: flask_login
, flask_principal
, flask_sqlalchemy
and
flask_migrate
; any other extension can be installed by being added to the core/extensions.py
file, inside the
install_extensions
function.
admin/
: An module example for an administration panel. CAN BE EDITED OR DELETEDblogs/
: An example module of the blogs tutorial project from the old Flask Quickstart Guide. CAN BE EDITED OR DELETEDcore/
: Core module of the application. This module contains the core code of the project and orchestrates the features of the template. This module contains the base templates and the static folder, also the authentication and permissions features. BE CAREFUL WHEN EDITING THE CODE INSIDE THIS FOLDER, THIS ACTION CAN BREAK THE PROJECTmigrations
: Contains all the migrations of the database. DO NOT MODIFY Should be modified using theflask-migrate
extension commands defined later in this file.web_page/
: An example module for the landing page. This folder contains the minimum code to create a module. CAN BE EDITED OR DELETEDapp.py
: Main file of the application. This file is the one that must be executed to run the application. DO NOT MODIFYmodules.py
: File that contains a set with the modules of the application. Only modify to add new modules to the set.
To install the project package, run the following command pip install -r requirements.txt
To create a new module, you only need to create a new folder with a module.py
file inside it. This file must contain a
class extending the core.AppModule
class and implementing the __init__
method defining the self.bluprint
attribute
with the blueprint of the module, the self.permission_names
attribute with at least an empty set and the self.template_folder
with the path to the module's templates folder. Also, you need to call the super __init__
method with the module name
as the parameter (You can see an example in admin/module.py
file).
To subscribe the module to the application, you need to import the module class in the modules.py
file and add it to the
APP_MODULES
set in it. This will allow the application to load the module when it starts.
Before running the project, you must create a .env
file in the root directory of the project as a copy of .env.example
.
Thanks to the flask_migrate
extension, the database can be created and updated automatically. To create the database,
you must run the following command: flask db migrate
. If you make any change to the models or add a new one you
must run the flask db migrate
command again and then flask db upgrade
to update the database.
If you want to renew the database migrations, you can delete the migrations
folder and run the flask db init
command.
Then you can run the flask db migrate
command to create the database tables.
To run the project you can use either the command python app.py
or flask run
To contribute to this project, you can fork the repository and create a pull request with your changes. Also, you can open an issue with your suggestion or bug report. I will be happy to review your contributions.