Generally, Flask is actually not an MVC framework. It is a minimalistic framework which gives you a lot of freedom in how you structure your application, but MVC pattern is a very good fit for what Flask provides.
This is how MVC app looks like , here flask_api is my app name , you can name it whatever you want , static folder contains our css files inside a css folder and images in images folder. Templates folder contains our html files whereas manage.py file contain host number to run app on particular local ip.
requirement.text file conatins packages information for installation.
MVC App folder layout:
As we can see, this app folder have bunch of files, i will explain each file functionalaty and purpose one by one.
- __init__.py this file use to initialise our app's urls and model , you can chek it.
- models.py this file is use to store data in database using ORM (object relational management sructure ) write now its empty but i will discuss in my upcoming post.
- settings.py file contains general setting regarding static , templates folder path , secret_key amd database details.
- urls.py file contains unique url for each functions which we defined in our views.py app.
- views.py this is core file of this app , it can contains multiple function , here we just write small functions just for bind up urls with app.
-
- Install python by the following command
sudo apt-get python3-pip
-
- Install requirement.txt file by the following command
pip install -r requirements.txt
- Now run the app on base dir where manage.py file is placed
- run this command here in your terminal python3 manage.py