Heroku / Django Connection拒绝:服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接?

时间:2017-07-06 20:18:58

标签: python django postgresql heroku ubuntu-12.04

2017-07-06T19:55:10.932781+00:00 heroku[web.1]: Starting process with command `python manage.py runserver 0.0.0.0:5303 --noreload`
2017-07-06T19:55:13.876394+00:00 app[web.1]: Performing system checks...
2017-07-06T19:55:13.876416+00:00 app[web.1]: 
2017-07-06T19:55:13.904755+00:00 app[web.1]: System check identified some issues:
2017-07-06T19:55:13.904757+00:00 app[web.1]: 
2017-07-06T19:55:13.904758+00:00 app[web.1]: WARNINGS:
2017-07-06T19:55:13.904773+00:00 app[web.1]: ?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DEBUG.
2017-07-06T19:55:13.904774+00:00 app[web.1]: 
2017-07-06T19:55:13.904775+00:00 app[web.1]: System check identified 1 issue (0 silenced).
2017-07-06T19:55:13.928308+00:00 app[web.1]: Traceback (most recent call last):
2017-07-06T19:55:13.928310+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
2017-07-06T19:55:13.928486+00:00 app[web.1]:     self.connect()
2017-07-06T19:55:13.928488+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
2017-07-06T19:55:13.928614+00:00 app[web.1]:     self.connection = self.get_new_connection(conn_params)
2017-07-06T19:55:13.928615+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
2017-07-06T19:55:13.928745+00:00 app[web.1]:     connection = Database.connect(**conn_params)
2017-07-06T19:55:13.928746+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
2017-07-06T19:55:13.928863+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2017-07-06T19:55:13.928866+00:00 app[web.1]: psycopg2.OperationalError: could not connect to server: Connection refused
2017-07-06T19:55:13.928867+00:00 app[web.1]:    Is the server running on host "localhost" (127.0.0.1) and accepting
2017-07-06T19:55:13.928867+00:00 app[web.1]:    TCP/IP connections on port 5432?
2017-07-06T19:55:13.928868+00:00 app[web.1]: 
2017-07-06T19:55:13.928870+00:00 app[web.1]: 
2017-07-06T19:55:13.928870+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2017-07-06T19:55:13.928871+00:00 app[web.1]: 
2017-07-06T19:55:13.928872+00:00 app[web.1]: Traceback (most recent call last):
2017-07-06T19:55:13.928898+00:00 app[web.1]:   File "manage.py", line 22, in <module>
2017-07-06T19:55:13.928981+00:00 app[web.1]:     execute_from_command_line(sys.argv)
2017-07-06T19:55:13.928983+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
2017-07-06T19:55:13.929156+00:00 app[web.1]:     utility.execute()
2017-07-06T19:55:13.929157+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
2017-07-06T19:55:13.929322+00:00 app[web.1]:     self.fetch_command(subcommand).run_from_argv(self.argv)
2017-07-06T19:55:13.929324+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
2017-07-06T19:55:13.929478+00:00 app[web.1]:     self.execute(*args, **cmd_options)
2017-07-06T19:55:13.929480+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 62, in execute
2017-07-06T19:55:13.929569+00:00 app[web.1]:     super(Command, self).execute(*args, **options)
2017-07-06T19:55:13.929571+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
2017-07-06T19:55:13.929732+00:00 app[web.1]:     output = self.handle(*args, **options)
2017-07-06T19:55:13.929734+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 101, in handle
2017-07-06T19:55:13.929831+00:00 app[web.1]:     self.run(**options)
2017-07-06T19:55:13.929833+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 112, in run
2017-07-06T19:55:13.929932+00:00 app[web.1]:     self.inner_run(None, **options)
2017-07-06T19:55:13.929933+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 128, in inner_run
2017-07-06T19:55:13.930036+00:00 app[web.1]:     self.check_migrations()
2017-07-06T19:55:13.930038+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 422, in check_migrations
2017-07-06T19:55:13.930232+00:00 app[web.1]:     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
2017-07-06T19:55:13.930233+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 20, in __init__
2017-07-06T19:55:13.930318+00:00 app[web.1]:     self.loader = MigrationLoader(self.connection)
2017-07-06T19:55:13.930319+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 52, in __init__
2017-07-06T19:55:13.930405+00:00 app[web.1]:     self.build_graph()
2017-07-06T19:55:13.930407+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph
2017-07-06T19:55:13.930540+00:00 app[web.1]:     self.applied_migrations = recorder.applied_migrations()
2017-07-06T19:55:13.930541+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
2017-07-06T19:55:13.930630+00:00 app[web.1]:     self.ensure_schema()
2017-07-06T19:55:13.930631+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
2017-07-06T19:55:13.930716+00:00 app[web.1]:     if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
2017-07-06T19:55:13.930718+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor
2017-07-06T19:55:13.930879+00:00 app[web.1]:     return self._cursor()
2017-07-06T19:55:13.930881+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor
2017-07-06T19:55:13.931014+00:00 app[web.1]:     self.ensure_connection()
2017-07-06T19:55:13.931015+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
2017-07-06T19:55:13.931145+00:00 app[web.1]:     self.connect()
2017-07-06T19:55:13.931146+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
2017-07-06T19:55:13.931242+00:00 app[web.1]:     six.reraise(dj_exc_type, dj_exc_value, traceback)
2017-07-06T19:55:13.931243+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
2017-07-06T19:55:13.931501+00:00 app[web.1]:     raise value.with_traceback(tb)
2017-07-06T19:55:13.931503+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
2017-07-06T19:55:13.931634+00:00 app[web.1]:     self.connect()
2017-07-06T19:55:13.931636+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
2017-07-06T19:55:13.931755+00:00 app[web.1]:     self.connection = self.get_new_connection(conn_params)
2017-07-06T19:55:13.931756+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
2017-07-06T19:55:13.931874+00:00 app[web.1]:     connection = Database.connect(**conn_params)
2017-07-06T19:55:13.931875+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
2017-07-06T19:55:13.931988+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2017-07-06T19:55:13.931992+00:00 app[web.1]: django.db.utils.OperationalError: could not connect to server: Connection refused
2017-07-06T19:55:13.931993+00:00 app[web.1]:    Is the server running on host "localhost" (127.0.0.1) and accepting
2017-07-06T19:55:13.931994+00:00 app[web.1]:    TCP/IP connections on port 5432?
2017-07-06T19:55:13.932015+00:00 app[web.1]: 

Django新手试图在http://www.gettingstartedwithdjango.com/introduction-and-launch.html

处完成项目的步骤

我在MacOX上,但是我正在使用vagrant ssh到Ubuntu 12.04机器。
我正在跑步:

$psql --version
psql (PostgreSQL) 9.4.12

$which psql
/usr/bin/psql

我尝试过的事情:

1

$service postgresql status
9.4/main (port 5432): online

2

$sudo netstat -nl | grep postgres
unix  2      [ ACC ]     STREAM     LISTENING     88800    /var/run/postgresql/.s.PGSQL.5432

3。

在我的postgresql.conf文件集中:`listen_addresses ='*'

    4。

    在我的settings/local.py

        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.postgresql_psycopg2',
                'NAME': 'microblog',
                'USER': 'vagrant',
                'PASSWORD': 'vagrant',
                'HOST': 'localhost',
                'PORT': '5432'
        }
    

    settings/base.py

    DATABASES = {
        'default': dj_database_url.config(default='postgres://vagrant:vagrant@localhost:5432/microblog')
    }
    

0 个答案:

没有答案