如何使用visual studio代码来调试django

时间:2016-12-02 17:10:29

标签: python django web-applications visual-studio-code atom-editor

我是 django 开发的新手,来自使用 Xcode 和相关IDE的桌面/移动应用开发。

我必须使用Django,我想知道是否有一种有效的方法使用 Visual Studio代码(或 Atom )进行调试。

任何与Django IDE相关的帮助也会有所帮助。

3 个答案:

答案 0 :(得分:28)

对于VSCode(完全披露,我是其中一位VSCode开发人员)尝试安装Python extension以开始使用。

This documentation covers debugging Django。应该有一个包含的调试配置,或者您可以将自己的配置添加到launch.json file

{
    "name": "Django",
    "type": "python",
    "request": "launch",
    "stopOnEntry": false,
    "pythonPath": "${config.python.pythonPath}",
    "program": "${workspaceRoot}/manage.py",
    "args": [
        "runserver",
        "--no-color",
        "--noreload"
    ],
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "RedirectOutput",
        "DjangoDebugging"
    ]
}

Python扩展还提供了许多其他有用的功能。

希望能帮助您入门。

答案 1 :(得分:0)

在禁用自动重装功能之前,对我没有任何帮助(--noreload是至关重要的,不确定是否会导致调试问题)

答案 2 :(得分:-1)

VSCode的官方教程对此进行了解释:

https://code.visualstudio.com/docs/python/tutorial-django

有很多步骤需要执行,我不想所有人都手动写出来,因为有很多步骤,但是我将尝试总结需要做的事情:

下面的文字基本上是上面教程的部分副本,我并不是说我自己想出来的。

1。确保检查出先决条件(使用VS Code Python扩展,在本地计算机上安装Python)link to docs

2。使用Python虚拟环境 link to docs

除了使用Python虚拟环境外,还需要在此虚拟环境中选择Python可执行文件作为VS Code中的解释器。可以这样做:

  

在VS Code中,打开“命令面板”(“视图”>“命令面板”或(Ctrl + Shift + P))。然后选择Python:选择解释器

然后,在虚拟环境中选择Python可执行文件,您可以通过其路径识别该文件。

3。创建调试器启动配置文件

as described here, in the documentation

“ VS代码”窗口的左上方)

4。现在您可以开始调试了

this part of the documentation will give you an introduction on how to do that

相关问题