3
votes

I'm making a Django app with the Two Scoops of Django template. Getting this Heroku error, are my Postgres production settings off?

  • OperationalError at / 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?
  • Exception Location: /app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py
  • foreman start works fine
  • Procfile: web: python www_dev/manage.py runserver 0.0.0.0:$PORT --noreload
  • local.py settings:

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

  • production.py settings: commented out local settings from above, added standard Heroku Django stuff:

    import dj_database_url DATABASES['default'] = dj_database_url.config()

    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

    ALLOWED_HOSTS = ['*']

    import os BASE_DIR = os.path.dirname(os.path.abspath(file)) STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/'

    STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), )

  • UPDATE: production settings, tried changing:

import dj_database_url DATABASES['default'] = dj_database_url.config(default=os.environ["DATABASE_URL"])

(named my Heroku color URL to DATABASE_URL, same link in heroku config)

1

1 Answers

4
votes

Have you set your DJANGO_SETTINGS_MODULE environment variable? I believe what is happening is this: by default Django is using your local.py settings, which is why it's trying to connect on localhost.

To make Django detect and use your production.py settings, you need to do the following:

heroku config:set DJANGO_SETTINGS_MODULE=settings.production

This will make Django load your production.py settings when you're on Heroku :)