Django manage.py runserver命令返回错误

时间:2018-03-15 21:37:40

标签: django localhost manage.py

我可以使用一些帮助来弄清楚为我的一个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时,我从来没有遇到过这样的事情,所以我会非常感谢每一个可能的解决方案。

2 个答案:

答案 0 :(得分:1)

听起来你正在使用Postgresql数据库并且它(数据库)没有回答

答案 1 :(得分:0)

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': '',
     }
}
相关问题