You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debugpy无法附加,VSCode调试Django项目断点失效求助

VSCode调试Docker中的Django应用无法触发断点

尝试了各种方法均无效,VSCode调试器无法触发任何断点。以下是相关配置文件及代码:

launch.json

{
  // 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: Docker",
      "type": "python",
      "request": "attach",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "/code"
        }
      ],
      "connect": {
        "host": "localhost",
        "port": 3000
      },
      "justMyCode": true,
      "logToFile": true
    }
}

docker-compose.yml

services:
  web:
    platform: linux/amd64
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8800:8000
      - 3000:3000

manage.py 代码片段

if settings.DEBUG:
    if os.environ.get('RUN_MAIN') or os.environ.get('WERKZEUG_RUN_MAIN'):
        import debugpy
        debugpy.listen(("0.0.0.0", 3000))
        # debugpy.wait_for_client()
        print('debugpy Attached!')

控制台已打印debugpy Attached!,说明Debugpy已加载,但断点仍无法触发。另外测试Django管理命令python manage.py myCommand,尝试用python -m debugpy --listen 0.0.0.0:3000 manage.py myCommand启动仍无效。

内容的提问来源于stack exchange,提问作者AlxVallejo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 17:45:12