Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a Django project from VSCODE

Is there a way to run a Django project from VSCODE editor?

Currently I use the windows CMD to run my project. Every time when I hit the button 'run' on VSCODE it doesn't run the project.

On pyCharm we can add 'runserver' to its script parameters configurations. Is there something like that on VSCODE?

UPDATE

I'm getting this on VSCODE terminal:

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

[Done] exited with code=0 in 9.449 seconds
like image 813
Filipe Avatar asked Sep 11 '25 04:09

Filipe


2 Answers

Here is how I did: From Terminal -> Configure Tasks...

{
"version": "2.0.0",
"tasks": [
    {
        "label": "Django: Run Server",
        "type": "shell",
        "command": "${config:python.pythonPath}",
        "args":[ 
               "manage.py",
               "runserver"
         ],
        "group": "none",
        "presentation": {
            "reveal": "always",
            "panel": "new"
           }
       }
   ]
}

Afterwards, it should show up, when you select Terminal -> Run Task...

like image 174
Şah-ı Merdan Avatar answered Sep 13 '25 19:09

Şah-ı Merdan


I'm in Linux if you are different environment please provide approprite command

Ctrl + Shift + p and type >python: Select Interpreter Please select your virtualenv which Django installed.

And Go to Debug ( Ctrl + Shift + d ) and these...

{
    // 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": "Django",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${workspaceRoot}/manage.py",
            "cwd": "${workspaceRoot}",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput",
                "DjangoDebugging"
            ]
        }
    ]
}
like image 38
Raja Simon Avatar answered Sep 13 '25 18:09

Raja Simon