Boilerplate for Flask-Python

Ashish Pratap Singh
3 min readFeb 6, 2020

--

Flask (Module View Template)

Many times a beginner gets stuck that how to build a complete flask project and modeling.

So, before starting to code, it’s better to create a private environment for each project(and activate it), in which you can install/import required libraries for the project.

This article will help you to get a start and structure of your project into code blocks and files that will help to easily understand and handle the code base and scale further.

Get Started:

First, we make a directory/root folder in which we will start the project and keep our codebase, files, and run.py file use to execute your project. (we can denote run.py file with any name according to your use.)

Flask directory/root folder

Project layout:

flask_MVC is the root folder containing all our files.

Inside the mvc directory create sub-directories and files as per your project requirements.

__init__.py: It’s a default python file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace. The __init__.py file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported.

__init__.py

database.py: This file contains the database for the file(here I use MongoDB for my project you can use any database according to your choice/need).

database.py

module.py: This file contains all requires modules for this project.

module.py

routes.py: It used to link all python files at a single place.

routes.py

Pipefile: This file contains all installed libraries which going to use in this project later.

pipefile use at project deployment time

Pipefile.lock: This file contains the source code of the module installed inside the Pipefile.

And the final run.py is used to run this project.

run.py

In the next article, I’ll show you how to deploy your project on Heroku and AWS web server.

Conclusion

This is kind of the basic structure we follow for coding websites. I have tried my best to explain as well as possible and hope it helps all fellow developers out there. I have uploaded a small project explaining the folder structure on GitHub for reference and you can find it here. If you liked this article, feel free to give it a clap or two and if you have any questions or queries, please leave them in the comments below.

Thank You. :)

--

--

No responses yet