无法访问 Django 服务器 http://127.0.0.1:8000/

4M0*_*M01 2 django python-3.x docker-compose

第一次它工作得很好,但现在显示了这个问题:

app$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
September 03, 2017 - 17:28:43
Django version 1.11.4, using settings 'aggregator.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Run Code Online (Sandbox Code Playgroud)

它说它正在运行,但我无法在该地址上访问它。可能出了什么问题?

我的 docker-compose 文件:

    version: "2"

services:
  postgres:
    image: postgres:9.6
    volumes:
      - pgdata:/var/lib/data/postgres

  backend:
    build: .
    command: gosu app bash
    volumes:
      - .:/app
      - pyenv:/python
    links:
      - postgres:postgres
    ports:
      - 8000:8000

volumes:
  pyenv:
  pgdata:
Run Code Online (Sandbox Code Playgroud)

小智 5

对于开发,您可以尝试将其设置为settings.py

ALLOWED_HOSTS = ['*']
Run Code Online (Sandbox Code Playgroud)

然后通过运行以下命令在本地启动服务器:

python manage.py runserver 0.0.0.0:8000
Run Code Online (Sandbox Code Playgroud)