
First and foremost, ensure you have the Python Extension installed in VSCode, so that you can run your Flask app using VSCode.

This assumes you have installed Python on your laptop. If your laptop is running Windows, you'll need to install Python on your Windows laptop. For example, let's say Python is installed at C:\Users\johndoe\AppData\Local\Programs\Python\Python312.

In this scenario, you'll probably want to select Edit environment variables for your account.

And create a variable that has value C:\Users\johndoe\AppData\Local\Programs\Python\Python312.

In VSCode Terminal, use pip install to install flask in Python. If you get "pip is not recognized as the name of a cmdlet, function, script file, or operable program" check out my article on installing pip on Windows.
PS C:\Users\jerem\Flask Web App> pip install flask
Requirement already satisfied: flask in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (2.2.2)
Requirement already satisfied: Werkzeug>=2.2.2 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from flask) (2.2.2)
Requirement already satisfied: Jinja2>=3.0 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from flask) (3.1.2)
Requirement already satisfied: itsdangerous>=2.0 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from flask) (2.1.2)
Requirement already satisfied: click>=8.0 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from flask) (8.1.3)
Requirement already satisfied: colorama in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from click>=8.0->flask) (0.4.6)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (from Jinja2>=3.0->flask) (2.1.1)
Just to get started, you can create a single file named main.py that contains the following.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World'
app.run()
Select main.py, click the Play button and then Run Python File.

If you get No Python interpreter is selected, you may need to close and re-open VSCode.

Go to http://127.0.0.1:5000/ and Hello World should be displayed.
Taking this a step further, in VSCode, create the following files.
AVOID TROUBLE
In this example, the name of the folder is "website". I ran into a unique problem once when I named the folder "email" since email.py is one of the built in modules that are part of the Python Standard Library included with your Python installation.
Flask uses the MVC (Model View Controller) Framework. Just to make this as obvious as possible, I like my Flask apps to have the following.
- Model -> models.py
- View -> views.py
- Controller -> __init__.py
Add the following to __init__.py.
from flask import Flask
def app():
app = Flask(__name__)
from .views import views
app.register_blueprint(views, url_prefix='/')
return app
Add the following to views.py.
from flask import Blueprint
views = Blueprint('views', __name__)
@views.route('/')
def home():
return "<h1>Hello World</h1>"
Add the following to main.py.
from website import app <- this line looks for a function named "app" in __init__.py
app = app()
if __name__ == '__main__':
app.run(debug=True)
On the main.py, click on the play icon, go to http://127.0.0.1:5000/ and Hello World should be displayed.
Did you find this article helpful?
If so, consider buying me a coffee over at