tech stack will include the following:
- virtualenv as a tool to create isolated Python environments
- SQLAlchemy ORM to be our ORM library of choice
- PostgreSQL optional. App already uses a local db
- Python3 and Flask as our server language and server framework
- Flask-Migrate for creating and running schema migrations
You can download and install the dependencies mentioned above using
pip
as:
pip install virtualenv
pip install SQLAlchemy
pip install Flask
pip install Flask-Migrate
├── README.md
├── app.py *** the main driver of the app. Includes your SQLAlchemy models.
"python app.py" to run after installing dependences
├── config.py *** Database URLs, CSRF generation, etc
├── requirements.txt *** The dependencies we need to install with "pip3 install -r requirements.txt"
├── static
│ ├── css
└── templates
├── layouts
└── pages
├── app.db *** Local DB - testing purpose
Overall:
- Models are located in the
MODELS
section ofapp.py
. - Controllers are also located in
app.py
. - The web frontend is located in
templates/
, which builds static assets deployed to the web server atstatic/
.
Highlight folders:
templates/pages
-- Defines the pages that are rendered to the site. These templates render views based on data passed into the template’s view, in the controllers defined inapp.py
.templates/layouts
-- Defines the layout that a page can be contained in to define footer and header code for a given page.app.py
-- Defines routes that match the user’s URL, and controllers which handle data and renders views to the user. This is the main app file that connects and manipulates the database and renders views with data to the user, based on the URL.- Models in
app.py
-- Defines the data models that set up the database tables. config.py
-- Stores configuration variables and instructions, separate from the main application code. This is where you will need to connect to the database if you want to connect to a DB like Postgres. However, the App already works with a local DB
- Initialize and activate a virtualenv using:
python -m virtualenv env
source env/bin/activate
Note - In Windows, the
env
does not have abin
directory. Therefore, you'd use the analogous command shown below:
source env/Scripts/activate
- Install the dependencies:
pip install -r requirements.txt
- Run the development server:
export FLASK_APP=app.py
export FLASK_ENV=development # enables debug mode
flask run
- Verify on the Browser
Navigate to project homepage http://127.0.0.1:5000/ or http://localhost:5000