Run Django server using the run button in visual studio code

Viewed 982

In pyCharm we have this option where we can configure Run button to start the server by adding the same to the script path.

enter image description here

I wanted to do the same in visual studio code, so that whenever I click Run, my django server gets started.

3 Answers

You need to create a launch.json in the folder .vscode which sits in the same folder as your manage.py.

// Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}\\manage.py",
            "args": [
                "runserver",
            ],
            "django": true
        },
    ]
}

You can create one by clicking run & debug and then at top menu green triangle click add configuration, python, Django

You can change the configuration in the Run and Debug sidebar:

enter image description here

  1. In vscode make sure your in the same folder as manage.py
  2. From the menu bar at top of vscode select TERMINAL -> NEW TERMINAL. (will launch a terminal window).
  3. In the terminal window type: python manage.py runserver
  4. Remember to keep the window open and minimized.
Related