Prerequisites:
-
Install the Python extension in vs code.
-
Install a version of Python 3/
-
On Windows, make sure the location of your Python interpreter is included in your PATH environment variable.
Steps:
-
Create a project folder for this tutorial, such as
hello_flask
. -
In that folder, use the following command (as appropriate to your computer) to create and activate a virtual environment named
.venv
based on your current interpreter:# macOs
python3 -m venv .venv
source .venv/bin/activate
# Windows
py -3 -m venv .venv
.venvscriptsactivate
3. Open the project folder in VS Code.
4. In VS Code, open the Command Palette (View > Command Palette or (Ctrl+Shift+P)). Then select the Python: Select Interpreter.
5. Install Flask in the virtual environment terminal.
python -m pip install flask
6. Now create a app.py file
# app.py
from flask import Flask
app = Flask(__name__)
@app.route(“/”)
def home():
return “Hello, Flask!”
7. run the app by entering
python -m flask run