In this lab you use Visual Studio Code remote development features to work on a Django+PostgreSQL application in a dockerized development environment.
IMPORTANT: Right now, you cannot use WSL as your shell to either open Visual Studio Code or as your default shell inside of Visual Studio Code and also use the VS Code Remote Extensions. To change the shell, press
Ctrl-Shift-P
and selectTerminal: Select Default Shell
. When prompted for a value, choose eitherCMD
orPowerShell
. Close any existing shells, and a new one will open with the selected default.
If you're doing this lab outside of the Microsoft booth at PyCon 2019, you'll need the following tools installed on your local machine:
- Docker Desktop
- Visual Studio Code Insider Build
- The VS Code Remote Extensions
- If you are running on windows, set your git line endings to use LF:
git config --global core.autocrlf false
-
Clone the sample app and open using Visual Studio Code:
git clone https://github.com/Microsoft/python-sample-tweeterapp cd python-sample-tweeterapp code-insiders .
-
Click the
Reopen in Container
prompt, or pressF1
and select theReopen folder in dev container
command. -
After the workspace terminal loads, open a new terminal using
Ctrl-Shift-`
and type the following to build the React frontend:npm install npm run dev
-
After the container builds, open another terminal using
Ctrl-Shift-`
and type:python manage.py migrate python manage.py loaddata initial_data python manage.py runserver
-
Open http://localhost:8000 in the browser to view the app.
-
Create an account and login to the app
- Stop the app in the terminal by pressing
Ctrl-C
(otherwise the port will be taken when you debug) - From the
Debug
menu, selectStart Debugging
. - Select the
Django
debug configuration from the menu. - Open
tweeter/views.py
, set a breakpoint on line 26 - Refresh the app in the browser to hit the breakpoint
- Open the debug console
Views > Debug Console
, and typerequest.user
into the debug console to inspect the logged in user