【问题标题】:Django manage.py runserver command returns an errorDjango manage.py runserver 命令返回错误
【发布时间】:2018-03-15 21:37:40
【问题描述】:

我可以使用一些帮助来找出为我的一个 django 项目运行开发服务器的问题。当我运行python managy.py runserver 时,我得到一个以这个结尾的错误:

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

在使用 Django 时,我从来没有遇到过这样的事情,所以我会非常感谢所有可能的解决方案。

【问题讨论】:

标签: django localhost manage.py


【解决方案1】:

听起来您正在使用 Postgresql 数据库,但它(数据库)没有响应

【讨论】:

    【解决方案2】:

    settings.py中,搜索这段代码,确认是否正确:

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
       }
    }
    

    然后启动postgresql数据库服务:

    systemctl start postgresql
    systemctl enable postgresql
    systemctl status postgresql  # Check if it is running correctly.
    

    更新:如果您熟悉数据库,那么最好设置自己的数据库服务器并使用凭据登录。

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'databasename',
        'USER': 'databaseuser',
        'PASSWORD': 'userpassword',
        'HOST' : 'localhost',
        'PORT': '',
         }
    }
    

    【讨论】:

    • 如果postgresql 抛出关于未找到不在目录中之类的错误。确保它是否在您的系统上:sudo apt-get install postgresql postgresql-contrib
    猜你喜欢
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2020-01-30
    • 2020-04-19
    • 1970-01-01
    相关资源
    最近更新 更多