这可能适用于其他命令,例如创建应用程序、超级用户等。
在 VSCode 中,使用 Open the Command Palette 执行任务(在 Linux 中为 Ctrl+Shift+P)。在那里,您输入/查找>Tasks: Run Task 并按回车键。然后选择配置一项任务。它将向您展示一个简单的回声示例:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
}
在这种情况下你编辑它,你可以执行python manage.py runserver,首先你可以尝试像这样添加它:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Runserver",
"type": "shell",
"command": "python manage.py runserver"
},
}
但是我得到了语法错误,这很奇怪,因为直接在 shell 上执行是可以的。因此,当我使用 environments 时,我明确指定了该环境的 python。
结果是
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Runserver",
"type": "shell",
"command": "./my_env_testing_blog/bin/python3 ./manage.py runserver",
},
]
}
"./my_env_testing_blog/ 是我的项目环境的路径。
所以,现在当我打开命令面板并选择Task: Run Task 选项时,会出现以下任务:Runserver
这可能适用于其他命令,例如创建应用程序、超级用户等。