当前位置: 首页 > 知识库问答 >
问题:

无法在Django上运行服务器(连接被拒绝)

纪翰
2023-03-14

我最终(认为)成功地安装了PostgreSQL和de psycopg2(我使用Windows)。顺便问一下,有什么方法可以检查它是否正常工作?

现在的问题是,我无法启动服务器,当我键入'python manage.py runserver'时,它显示(在命令末尾):

conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 8000?
could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 8000?
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1            md5
# IPv6 local connections:
host    all             all             127.0.0.1            md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
# - Connection Settings -

listen_addresses = 'localhost'      # what IP address(es) to listen on;
                # comma-separated list of addresses;
                # defaults to 'localhost'; use '*' for all
                # (change requires restart)
port = 8000             # (change requires restart)
max_connections = 100           # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = ''   # comma-separated list of directories
                # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                # (change requires restart)
#bonjour = off              # advertise server via Bonjour
                # (change requires restart)
#bonjour_name = ''          # defaults to the computer name
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'database1',                      
    'USER': 'root',
    'PASSWORD': '123456',
    'HOST': 'localhost',
    'PORT': '8000',
    }
}

编辑1:我尝试将settings.py端口更改为5432,但现在错误消息是相同的,只是更改端口:

could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

配置文件是这样的吗?我该换点东西吗?我找不到答案。我尝试使用python manage.py runserver,两者都指示127.0.0.1:8000和8001,但错误消息没有变化。出什么问题了?非常感谢。

共有1个答案

齐浩淼
2023-03-14

对我来说,这是因为postgres没有启动和启用。所以我这样做解决了问题:

sudo systemctl start postgresql
sudo systemctl enable postgresql
 类似资料:
  • 每次运行Rails4.0服务器时,都会得到这个输出。 我正在运行小牛OS X10.9,所以我不知道这是不是问题所在。我已经试了我能试的一切,但似乎都没有效果。我已经卸载并安装了postgres和pg gem多次了。 这是我的database.yml文件

  • 问题内容: 我正在尝试使用Flask在Raspberry Pi上运行一个简单的Web服务器。当我运行Flask应用程序时,它说: 在http://127.0.0.1:5000/上运行 但是,当我在笔记本电脑的Chrome中输入此地址时, ERR_CONNECTION_REFUSED 我可以在Raspberry Pi的浏览器上打开127.0.0.1:5000。我需要怎么做才能从另一台计算机连接? 问

  • 我正在尝试连接两个docker容器,一个是posgresql,另一个是python flask应用程序。两者都链接正确,python应用程序中的所有连接变量都直接取自postgres容器中通过链接公开的连接变量,并且与检查postgresql容器时发现的连接变量相同。当我将psql与连接字符串中的精确参数一起使用时,即: 成功连接到postgres容器中的数据库,因此我知道postgres正在通过

  • 因此,我的计划是编写一个dockerfile,使用基本映像,然后在其中复制并运行。 SQL脚本:db0.SQL DockerFile:db0.dockerFile null 完成这些操作后,我可以用一个python_team数据库、一个带有示例表的测试模式和一条记录连接到它。 怎么解决?

  • 我正在docker容器中运行sql server` 所有这些都成功完成了。现在,当我尝试使用Java连接到数据库时,我得到了错误。 192.168.56.101是我的虚拟机的ip。我正在虚拟机上运行Linux。 我收到通信链路故障错误。 我在谷歌上搜索并找到了一些关于以下链接的解决方案,但没有一个对我有用。 使用JDBC和MySQL解决“通信链路故障” 如何连接docker中作为容器运行的MySQ

  • 问题内容: 前几天,我的GoDaddy托管网站遇到了一些问题。我打电话给他们的技术支持,与我交谈的人建议我的问题与我在Windows机器上,最好在Linux机器上使用有关。我对此没有意见,我同意了,他们把我换了。 过渡之后,我的PHPMailer功能让我迷茫了。我已经工作了几个月,所以我知道我的设置是正确的。我已与GoDaddy确认,从他们的角度来看,我要发送的帐户并未更改。用户侧未进行任何更改(