Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 2.52 KB

File metadata and controls

59 lines (43 loc) · 2.52 KB

Developing a Django+PostgreSQL application in a Dev Container

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 select Terminal: Select Default Shell. When prompted for a value, choose either CMD or PowerShell. Close any existing shells, and a new one will open with the selected default.

Prerequisites

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:

  1. Docker Desktop
  2. Visual Studio Code Insider Build
  3. The VS Code Remote Extensions
  4. If you are running on windows, set your git line endings to use LF:
    git config --global core.autocrlf false
    

Open the dev container workspace

  1. 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 .
  2. Click the Reopen in Container prompt, or press F1 and select the Reopen folder in dev container command.

  3. 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
  4. 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
  5. Open http://localhost:8000 in the browser to view the app.

  6. Create an account and login to the app

Set up debugging in the container

  1. Stop the app in the terminal by pressing Ctrl-C (otherwise the port will be taken when you debug)
  2. From the Debug menu, select Start Debugging.
  3. Select the Django debug configuration from the menu.
  4. Open tweeter/views.py, set a breakpoint on line 26
  5. Refresh the app in the browser to hit the breakpoint
  6. Open the debug console Views > Debug Console, and type request.user into the debug console to inspect the logged in user