首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法用vs-代码连接到容器中运行的django进程。

无法用vs-代码连接到容器中运行的django进程。
EN

Stack Overflow用户
提问于 2019-10-13 17:48:25
回答 1查看 923关注 0票数 0

我在连接使用vs代码生成的容器中运行的django进程时遇到了问题。一切似乎都正常,我得到了服务器的启动消息,但是当连接到localhost:8000时,我没有得到响应.

启动容器时,我会收到一条已发布的端口消息:

发布的端口: 8000/tcp -> 127.0.0.1:8000

在启动launch.json调试时,也是一个干净的开始。

系统检查没有发现任何问题(0被沉默)。2019年10月13日-17:45:45:05 Django版本2.2.6,使用设置‘fpl django.set’在http://127.0.0.1:8000/启动开发服务器,退出带有CONTROL的服务器。

为什么我不能访问这个网站: localhost:8000?

devcontainer.json:

代码语言:javascript
复制
    // For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
  "name": "Existing Dockerfile",
  // Sets the run context to one level up instead of the .devcontainer folder.
  "context": "..",
  // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
  "dockerFile": "../docker/dev/python/Dockerfile",
  // The optional 'runArgs' property can be used to specify additional runtime arguments.
  "runArgs": [
    // Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker for details.
    // "-v","/var/run/docker.sock:/var/run/docker.sock",
    // Uncomment the next line if you will be using a ptrace-based debugger like C++, Go, and Rust.
    // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
    // You may want to add a non-root user to your Dockerfile. On Linux, this will prevent
    // new files getting created as root. See https://aka.ms/vscode-remote/containers/non-root-user
    // for the needed Dockerfile updates and then uncomment the next line.
    // "-u", "vscode"
    "--network",
    "fpl-django_default"
  ],
  // Use 'settings' to set *default* container specific settings.json values on container create.
  // You can edit these settings after create using File > Preferences > Settings > Remote.
  "settings": {
    "terminal.integrated.shell.linux": "/bin/bash",
    "python.pythonPath": "/usr/local/bin/python",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintPath": "/usr/local/bin/pylint",
    "python.linting.enabled": true
  },
  // Uncomment the next line if you want to publish any ports.
  "appPort": [
    8000
  ],
  // Uncomment the next line to run commands after the container is created - for example installing git.
  // "postCreateCommand": "apt-get update && apt-get install -y git",
  // Add the IDs of extensions you want installed when the container is created in the array below.
  "extensions": [
    "ms-python.python",
  ]
}

launch.json:

代码语言:javascript
复制
    {
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Django",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/manage.py",
      "console": "integratedTerminal",
      "args": [
        "runserver",
        "--noreload",
        "--nothreading"
      ],
      "django": true
    }
  ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-19 16:19:41

尝试使用这个param:0.0.0.0:8000运行manage.py runserver,这将告诉您的应用程序侦听来自任何主机的请求。就像这样:

代码语言:javascript
复制
{
      "name": "Python: Django",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/manage.py",
      "console": "integratedTerminal",
      "args": [
        "runserver",
        "0.0.0.0:8000",
        "--noreload",
        "--nothreading"
      ],
      "django": true
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58366220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档