|
| 1 | +# Hello World in Visual Studio Codespaces |
| 2 | + |
| 3 | +In this lab you will create a hello world script in Visual Studio Codespaces to experiment with the development experience on the browser. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +You'll need the following tools installed on your local machine: |
| 8 | + |
| 9 | +1. A [supported browser](https://docs.microsoft.com/en-us/visualstudio/online/resources/troubleshooting#partially-supported-browsers) |
| 10 | +1. Azure Credentials. |
| 11 | + |
| 12 | +## Create a Codespace |
| 13 | +1. Navigate to https://aka.ms/vscodespaces, click on the "Sign in" button and enter your Azure credentials. |
| 14 | +1. Click on the "Create Workspace" button, and add "HelloWorld" to the `Codespace Name` field. |
| 15 | +1. Add https://github.com/luabud/hello-vscodespaces to the `Git repository` field. This repo contains a simple Hello World Flask application. |
| 16 | +1. Click on the "Create" button. You can leave the other fields with the default values. |
| 17 | + |
| 18 | +## Create a Hello World script |
| 19 | +1. Open the Command Palette (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>, or <kbd>Command</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> if you're on macOS) and run the `File: New File` command. |
| 20 | +1. Name it `hello.py`, and open it on VS Codespaces. |
| 21 | +1. Add `print("Hello, VS Codespaces!")` to the file and save it (<kbd>Ctrl</kbd> + <kbd>S</kbd>). |
| 22 | +1. Click on the green play button on the top right, next to your file name open on the editor. This will run your hello world script in the terminal. |
| 23 | + |
| 24 | +## Debug the Hello World Flask app |
| 25 | + |
| 26 | +1. Check that VS Codespaces created a virtual environment called `pythonenv3.7` located on the top of the project. |
| 27 | +1. 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. |
| 28 | +1. Start a debug session : |
| 29 | + |
| 30 | + - 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. |
| 31 | + |
| 32 | + - Or press <kbd>F5</kbd> |
| 33 | +1. From the configuration drop-down, select "Flask" |
| 34 | +1. You should see the following message on the terminal: |
| 35 | +``` |
| 36 | + * Serving Flask app "app.py" |
| 37 | + * Environment: development |
| 38 | + * Debug mode: off |
| 39 | + * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) |
| 40 | + ``` |
| 41 | + 6. Press <kbd>Ctrl</kbd> and click on the link on the terminal to access the application on a new tab. |
| 42 | + |
| 43 | + |
| 44 | +## Additional things to try |
| 45 | +1. **Edit:** |
| 46 | + - Open `app.py` |
| 47 | + - Try adding some code and check out the language features. |
| 48 | + |
| 49 | +1. **Try out Flask live reloading while debugging:** |
| 50 | + |
| 51 | + - Create a configuration file for the debugger by opening the Run/Debug view and clicking on "create a launch.json file" |
| 52 | + - Select Flask from the configuration options |
| 53 | + - Delete lines 19 and 20 ("--no-debugger" and "--no-reload") |
| 54 | + - Change "FLASK_DEBUG" on line 15 to "1". |
| 55 | + - Press <kbd>F5</kbd> to start the debug session using that new configuration |
| 56 | + - Open the `app.py` file, make a change and save it. |
| 57 | +1. **Add a logpoint**: |
| 58 | + |
| 59 | + - Open `app.py` and right click on the left side of line 5 |
| 60 | + - Select `Add logpoint...` |
| 61 | + - Enter "Executing endpoint" and hit <kbd>Enter</kbd> |
| 62 | + - Press F5 to run the Flask app and <kbd>Ctrl</kbd> + Click on the link to open it on a new tab |
| 63 | + - Open the Debug Console panel (next to the terminal) and see the logged message. |
| 64 | + |
| 65 | + |
| 66 | +## Other samples |
| 67 | +- [Tweeter App - Python and Django](https://github.com/Microsoft/python-sample-tweeterapp) |
| 68 | +- [The Cat Said No - Python and Flask](https://github.com/luabud/TheCatSaidNo) |
0 commit comments