This video is available to students only

Setting up a new Flask Application

Here are the steps to set up the foundation for a maintainable Flask application.

  1. Create a folder for our new application called yumroad-app
  2. With your terminal, create a virtual environment in the yumroad-app folder by running python3 -m venv env
  3. Activate the Virtual Environment by running source env/bin/activate in your terminal (You should see your prompt prefixed with a (env) to know that your virtual env is activated)
caution

Your virtualenv needs to be activated in every terminal session where you plan to run the application If you open a new tab or window for example and want to run commands that depend on things installed within the virtual environment, you'll need to run the activation command again.

  1. Create a requirements.txt that lists the following starting libraries as requirements
flask
gunicorn

pytest
pytest-flask
pytest-cov
  1. Install those libraries by running pip install -r requirements.txt
  2. Create a folder called yumroad and then a file called __init__.py within the yumroad folder
  3. Setup the basic application factory pattern in the __init__.py file
from flask import Flask

def create_app(environment_name='dev'):
    app = Flask(__name__)
    return app

Start a new discussion. All notification go to the author.