In this lab you use Visual Studio Code remote development features to work on a Django + PostgreSQL application in a dockerized development environment.
You'll need the following tools installed on your local machine:
- Docker Desktop
- Visual Studio Code
- 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
-
On a terminal, clone the sample app and open using Visual Studio Code:
git clone https://github.com/Microsoft/python-sample-tweeterapp cd python-sample-tweeterappand:
code .
or if you are using Visual Studio Code Insiders:
code-insiders .
-
Click the
Reopen in Containerprompt, or pressF1and select theReopen folder in dev containercommand. -
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
Debugmenu, selectStart Debugging. - Select the
Djangodebug 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.userinto the debug console to inspect the logged in user