Related Tutorial

1: Install Flask on Window with Visual Studio Code

1) Open Visual Studio Code.

2) Click on “File” in the menu and select “Open Folder”

3) Go to the directory where your Flask project is located and then select the folder to open it in VS Code.

4) The next step is Setting up a Virtual Environment: Write the following command to create a virtual environment in the terminal of Visual Studio code

				
					python -m venv env
				
			

Run the virtual environment through this command:

				
					.\env\Scripts\activate
				
			

Install Flask :

				
					pip install Flask
				
			

Install the Python Extension in VS Code:

Select Extention from menu from Left panel in visual studio code (or press Ctrl+Shift+X).
Search for “Python” in the Extensions.
Install the “Python” extension by Microsoft.


Configure the Python Interpreter:

Open the Command Palette by pressing Ctrl+Shift+P.
Search “Python then Select Interpreter” and choose the interpreter from the virtual environment you created.

 

Create a Flask App:

Create a Python file (e.g., test.py) in your project directory.
Write your Flask application code in the test.py file.

here is the example code:

				
												from flask import Flask

							app = Flask(__name__)

							@app.route('/')
							def hello_world():
								return 'Hello, World!'

							if __name__ == '__main__':
								app.run()
				
			

Run your Flask application by right-clicking on the file and selecting “Run Python File in Terminal”.
For running Flask application, you can use the integrated terminal in VS Code and run python app.py.

Thank you.