我只是将Django应用移动到使用docker, 但是当我尝试使用调试器时,现在它消失了,甚至没有输出调试控制台日志
我已经将以下代码添加到manage.py
# Allow other computers to attach to ptvsd at this IP address and port.
ptvsd.enable_attach(address=("localhost", 8001), redirect_output=True)
# Pause the program until a remote debugger is attached
ptvsd.wait_for_attach()
已经在docker compose文件中打开了8001端口进行调试
a-django-app:
....
command: ./wait-for-it.sh postgis:5432 -s -- python3 manage.py runserver 0.0.0.0:8000 --enable-debugging
ports:
- "8000:8000"
- "8001:8001"
这是我的启动.json配置
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Attach (Docker)",
"type": "python",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}/",
"remoteRoot": "/usr/src/ADjangoApp/"
}
],
"port": 8001, // Set to the remote port.
"host": "localhost" // Set to your remote host's public IP address.
},
]
}
命令流程: