gpt4 book ai didi

django - 从Docker连接Postgres

转载 作者:行者123 更新时间:2023-12-02 20:56:44 25 4
gpt4 key购买 nike

我在ubuntu18.04中安装了postgres,并在端口5432上运行。
enter image description here
我在Django中有Django应用程序及其应用程序。
我的settings.py文件中的数据库连接如下所示。

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbname',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': 5432,
}
}
当我运行 sudo docker-compose run命令时,出现以下错误。
enter image description here

最佳答案

Django应用程序中的127.0.0.1指的是Docker容器中的localhost,而不是您的主机。
获取您的Ubuntu主机的IP,例如通过运行ifconfig,并将您的Django应用程序配置为使用该IP。

关于django - 从Docker连接Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62536042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com