【发布时间】:2016-10-21 14:25:15
【问题描述】:
当我从 Visual Studio 代码中按下运行按钮(或 F5)时,我想自动启动 Python http.server。 我认为这是 launch.json 配置的问题,但我不熟悉它。 我该怎么做?
【问题讨论】:
标签: visual-studio-code simplehttpserver
当我从 Visual Studio 代码中按下运行按钮(或 F5)时,我想自动启动 Python http.server。 我认为这是 launch.json 配置的问题,但我不熟悉它。 我该怎么做?
【问题讨论】:
标签: visual-studio-code simplehttpserver
请安装 pythonVSCode 扩展。并在您的项目目录中创建 python 文件。并将以下内容放在上面。参考here
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
然后像这样创建启动配置...
{
"name": "Documentation",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${workspaceRoot}/env/bin/python",
"program": "${workspaceRoot}/your_pyton_run_file.py",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
然后你可以用 F5 开始这个
【讨论】: