In this article, I am showing you what I feel is a simple, easy setup to begin a flask project and some code to start building in Flask . I am using** Visual Studio Code**  for this project.

Initial Setup

I am creating a virtual environment to develop my project. If you don’t want virtual env, you can go ahead and use the global system space.

By using **venv **in python library we can create a virtual environment. The command python -m venv (name of env) creates a virtual environment with the specified name. Here it is “venv” itself. Now we have to activate the environment with venv\Script\activate command. Once activated we can see our env name in green color as shown. To deactivate we just need to use deactivate command.

Image for post

Upgrade pip and install flaskflask-WTF (module for wtf-forms only if you need it), python-dotenv.

pip install flask flask-wtf python-dotenv

The module python-dotenv enables us to set flask environment variables using a separate file. Create a **.flaskenv set **theFLASK_ENV and FLASK_APP variables as shown. FLASK_ENV indicates the type of environment i.e whether the app is under development or production.FLASK_APP specifies the module from which the flask app starts executing. In other words, the file that is first executed when you hit the flask run command to start the server. We will use the flask run command at the end.

FLASK_ENV=development
FLASK_APP=main.py

Now we create a requirements.txt file with below command that contains all the modules required for our app to run, so when we want to run our application on a different machine we can use this file and install using below command.

pip freeze > requirements.txt
pip install -r requirements.txt

Next, create the following directory structure as per your application.

Image for post

Directory Structure for the demo project.

#python #python-flask #flask #dero-project #project-setup

Deploy your ML model with Flask: Setup and Demo Project
1.85 GEEK