In this lab you will create a hello world script in Visual Studio Codespaces to experiment with the development experience on the browser.
You'll need the following tools installed on your local machine:
- A supported browser
- Azure Credentials.
- Navigate to https://aka.ms/vscodespaces, click on the "Sign in" button and enter your Azure credentials.
- Click on the "Create Codespace" button, and add "HelloWorld" to the
Codespace Name
field. - Add https://github.com/asw101/hello-vscodespaces to the
Git repository
field. This repo contains a simple Hello World Flask application. - Click on the "Create" button. You can leave the other fields with the default values.
- Open the Command Palette (Ctrl + Shift + P, or Command + Shift + P if you're on macOS) and run the
File: New File
command. - Name it
hello.py
, and open it on VS Codespaces. - Add
print("Hello, VS Codespaces!")
to the file and save it (Ctrl + S). - Right click on the editor select
Run Python File in Terminal
. This will run your hello world script in the terminal.
-
Check that VS Codespaces created a virtual environment called
pythonenv3.7
located on the top of the project. -
Make sure this environment is selected by clicking on the Python environment information on the status bar, localted on the bottom left of the screen.
-
Start a debug session :
-
Open the Run/Debug view by clicking on the play + bug icon on the activity bar, on the left side of the screen. Then click on the "Run and Debug" button.
-
Or press F5
-
-
From the configuration drop-down, select "Flask"
-
You should see the following message on the terminal:
* Serving Flask app "app.py"
* Environment: development
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Press Ctrl and click on the link on the terminal to access the application on a new tab.
-
Edit:
- Open
app.py
- Try adding some code and check out the language features.
- Open
-
Try out Flask live reloading while debugging:
- Create a configuration file for the debugger by opening the Run/Debug view and clicking on "create a launch.json file"
- Select Flask from the configuration options
- Delete lines 19 and 20 ("--no-debugger" and "--no-reload")
- Change "FLASK_DEBUG" on line 15 to "1".
- Press F5 to start the debug session using that new configuration
- Open the
app.py
file, make a change and save it.
-
Add a logpoint:
- Open
app.py
and right click on the left side of line 5 - Select
Add logpoint...
- Enter "Executing endpoint" and hit Enter
- Press F5 to run the Flask app and Ctrl + Click on the link to open it on a new tab
- Open the Debug Console panel (next to the terminal) and see the logged message.
- Open