当我使用 Kong gateway 时,Django 管理页面打不开

问题描述 投票:0回答:1

我使用 Kong gateway 使 Django 项目可以在

localhost/python
访问。我可以看到 Django 起始页,但是当我尝试打开
localhost/python/admin
时,它会重定向到
localhost/admin/login/?next=/admin/
,因此这不再是 Django 项目。我能做什么来解决这个问题?谢谢

这就是 Kong 的服务和路线:

{
  "enabled": true,
  "tls_verify": null,
  "tls_verify_depth": null,
  "port": 3000,
  "protocol": "http",
  "path": null,
  "client_certificate": null,
  "write_timeout": 60000,
  "connect_timeout": 60000,
  "retries": 5,
  "read_timeout": 60000,
  "id": "8da72803-ffea-4424-a568-31faa3782a6d",
  "name": "python-service",
  "host": "python-service",
  "updated_at": 1711390446,
  "created_at": 1711390446,
  "tags": null,
  "ca_certificates": null
}

路线:

{
  "next": null,
  "data": [
    {
      "strip_path": true,
      "regex_priority": 0,
      "methods": null,
      "request_buffering": true,
      "response_buffering": true,
      "protocols": [
        "http",
        "https"
      ],
      "service": {
        "id": "8da72803-ffea-4424-a568-31faa3782a6d"
      },
      "https_redirect_status_code": 426,
      "tags": null,
      "paths": [
        "/python"
      ],
      "headers": null,
      "id": "2c1fb24a-21dd-42f5-9784-a3bf95c6f7dc",
      "path_handling": "v0",
      "created_at": 1711390464,
      "updated_at": 1711390464,
      "name": null,
      "snis": null,
      "sources": null,
      "hosts": null,
      "preserve_host": false,
      "destinations": null
    }
  ]
}
python python-3.x django django-admin kong
1个回答
0
投票

。我用了 `CMD shell -c '导入系统; print(sys.path[0])' 检查每一个:

  • manage.py
    将自己的位置添加到 python 路径中。没事儿 因为
    django-admin startproject
    将它放在项目旁边 目录。

  • django-admin
    还将自己的位置添加到python路径中。那是 不太好,因为通常是 /some/venv/bin/ 之类的东西,所以 项目包不可导入。仅运行
    django-admin runserver --settings=example.settings
    会失败并显示
    ModuleNotFoundError: No module named 'example'

  • python -m django
    使用当前目录,稍微少一点 比manage.py有用,但非常直观。

当然,您可以通过显式设置 PYTHONPATH 来规避所有这些。

© www.soinside.com 2019 - 2024. All rights reserved.