如何使用visual studio代码调试django
How to use visual studio code to debug django
我是 django 开发的新手,来自 desktop/mobile 应用程序开发 Xcode 及相关IDE.
我必须使用 Django,我想知道是否有使用 Visual Studio Code(或 Atom).
任何与 Django 相关的帮助 IDE 也会有所帮助。
对于 VSCode(完全公开,我是 VSCode 开发人员之一)尝试安装 Python extension 开始。
This documentation covers debugging Django. There should be a included debug configuration or you can add your own to the 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 扩展还提供了许多您可能会觉得有用的其他功能。
希望对您有所帮助。
只有实验性配置适合我。
{
"name": "Django",
"type": "pythonExperimental",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
标准配置导致 Unverified breakpoint
问题。
VSCode有官方教程解释这个:
https://code.visualstudio.com/docs/python/tutorial-django
有几个步骤需要做,我不想都手动写出来,因为有很多步骤,但我会尽量总结需要做的事情:
下面的文字基本上是上面教程的部分复制,并不是我自己想出来的。
1.确保检查先决条件(使用 VS Code Python 扩展,在本地计算机上安装 Python)link to docs
2。使用Python虚拟环境link to docs
除了使用Python虚拟环境外,您还需要select这个虚拟环境中的Python可执行文件作为VS Code中的解释器。可以这样做:
In VS Code, open the Command Palette (View > Command Palette or (Ctrl+Shift+P)). Then select the Python: Select Interpreter
然后你 select 你的虚拟环境中的 Python 可执行文件,你可以通过它的路径识别它。
3。创建调试器启动配置文件
as described here, in the documentation
VS Code 左上window)
4.现在可以开始调试了
this part of the documentation will give you an introduction on how to do that
在我禁用自动重新加载之前对我没有任何作用(--noreload
因为参数很重要,不确定为什么它会导致调试问题)
{
// 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
},
{
"name": "Django: makemigrations",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\manage.py",
"args": [
"makemigrations"
],
"django": true
},
{
"name": "Django: migrate",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\manage.py",
"args": [
"migrate"
],
"django": true
},
]
}
我是 django 开发的新手,来自 desktop/mobile 应用程序开发 Xcode 及相关IDE.
我必须使用 Django,我想知道是否有使用 Visual Studio Code(或 Atom).
任何与 Django 相关的帮助 IDE 也会有所帮助。
对于 VSCode(完全公开,我是 VSCode 开发人员之一)尝试安装 Python extension 开始。
This documentation covers debugging Django. There should be a included debug configuration or you can add your own to the 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 扩展还提供了许多您可能会觉得有用的其他功能。
希望对您有所帮助。
只有实验性配置适合我。
{
"name": "Django",
"type": "pythonExperimental",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
标准配置导致 Unverified breakpoint
问题。
VSCode有官方教程解释这个:
https://code.visualstudio.com/docs/python/tutorial-django
有几个步骤需要做,我不想都手动写出来,因为有很多步骤,但我会尽量总结需要做的事情:
下面的文字基本上是上面教程的部分复制,并不是我自己想出来的。
1.确保检查先决条件(使用 VS Code Python 扩展,在本地计算机上安装 Python)link to docs
2。使用Python虚拟环境link to docs
除了使用Python虚拟环境外,您还需要select这个虚拟环境中的Python可执行文件作为VS Code中的解释器。可以这样做:
In VS Code, open the Command Palette (View > Command Palette or (Ctrl+Shift+P)). Then select the Python: Select Interpreter
然后你 select 你的虚拟环境中的 Python 可执行文件,你可以通过它的路径识别它。
3。创建调试器启动配置文件
as described here, in the documentation
VS Code 左上window)
4.现在可以开始调试了
this part of the documentation will give you an introduction on how to do that
在我禁用自动重新加载之前对我没有任何作用(--noreload
因为参数很重要,不确定为什么它会导致调试问题)
{
// 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
},
{
"name": "Django: makemigrations",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\manage.py",
"args": [
"makemigrations"
],
"django": true
},
{
"name": "Django: migrate",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\manage.py",
"args": [
"migrate"
],
"django": true
},
]
}