Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 2.12 KB

File metadata and controls

62 lines (46 loc) · 2.12 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.

Prerequisites

You'll need the following tools installed on your local machine:

  1. Docker Desktop
  2. Visual Studio Code
  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
    

Create the dev container workspace

  1. 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-tweeterapp

    and:

    code .

    or if you are using Visual Studio Code Insiders:

    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