Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Postgresql syncdb错误_Python_Django_Localhost - Fatal编程技术网

Python Django Postgresql syncdb错误

Python Django Postgresql syncdb错误,python,django,localhost,Python,Django,Localhost,运行python manage.py syncdb时,出现以下错误: OperationalError: could not translate host name "localhost" to address: nodename nor servname provided, or not known my settings.py文件如下所示: if "IS_STAGING" in os.environ or "IS_PRODUCTION" in os.environ: import

运行python manage.py syncdb时,出现以下错误:

OperationalError: could not translate host name "localhost" to address: nodename nor servname provided, or not known
my settings.py文件如下所示:

if "IS_STAGING" in os.environ or "IS_PRODUCTION" in os.environ:
    import dj_database_url
    DATABASES = {'default':dj_database_url.config(default='postgres://localhost')}
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'test',                      # Or path to database file if using sqlite3.
            # The following settings are not used with sqlite3:
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
            'PORT': '',                      # Set to empty string for default.
        }
    }

这个错误我已经犯过好几次了。如果试图连接到本地数据库,最好将主机作为空字符串保留:

'HOST':''

如果这不起作用,应采取以下措施:


'HOST':'127.0.0.1'

本地主机是在您的/etc/hosts中定义的吗?'nslookup localhost'在您的计算机中返回什么?您尝试只输入127.0.0.1或将该行留空?glasslion,localhost在我的etc/hosts.txt文件中定义为:127.0.0.1 localhostnslookup localhost'返回:Server:128.32.136.9地址:128.32.136.9#53**服务器找不到localhost:NXDOMAIN