title: Django admin giving internal server error 500
body: <p>My django and python knowledge is not very deep. I followed the Django tutorial (1.7) and then created an app for someone to update a list of people via the django admin. I have it working locally, and it works as well on my staging server.</p>
  
  <p>On production, the site works, and I can get to the admin log in page. But when I log in, I get a 500 Internal Server Error. I've spent about two days trying to debug this. </p>
  
  <p>The Apache error log shows "[Errno 111] Connection refused" but lots of googling that text has turned up nothing I can use yet.</p>
  
  <p>Based on some of the related conversations I've found on here,they seem to focus on using django to send email (I'm not). </p>
  
  <p>I think I've got my Allowed Hosts configured correctly, since I can see the non-admin site.</p>
  
  <p>I've compared the apache configs and file permissions between the staging server and the production server, and they all seem to be the same.</p>
  
  <p>Any help you may be able to offer would be greatly appreciated. Thank you.</p>
  
  <p><strong>error.log</strong></p>
  
  <pre><code>[wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664] mod_wsgi (pid=26646): Exception occurred processing WSGI script '/home/admin/dj-1.7/accountedge/trunk/accountedge/accountedge/wsgi.py'., referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664] Traceback (most recent call last):, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     response = self.get_response(request), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info()), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 231, in handle_uncaught_exception, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     'request': request, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self._log(ERROR, msg, args, **kwargs), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/logging/__init__.py", line 1271, in _log, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self.handle(record), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/logging/__init__.py", line 1281, in handle, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self.callHandlers(record), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/logging/__init__.py", line 1321, in callHandlers, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     hdlr.handle(record), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/logging/__init__.py", line 749, in handle, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self.emit(record), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/utils/log.py", line 132, in emit, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     connection=self.connection()), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     mail.send(fail_silently=fail_silently), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/mail/message.py", line 286, in send, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     return self.get_connection(fail_silently).send_messages([self]), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     new_conn_created = self.open(), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/home/admin/dj-1.7/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 50, in open, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self.connection = connection_class(self.host, self.port, **connection_params), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/smtplib.py", line 251, in __init__, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     (code, msg) = self.connect(host, port), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/smtplib.py", line 311, in connect, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     self.sock = self._get_socket(host, port, self.timeout), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/smtplib.py", line 286, in _get_socket, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     return socket.create_connection((host, port), timeout), referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]   File "/usr/lib/python2.7/socket.py", line 571, in create_connection, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664]     raise err, referer: ***.com/admin/login/?next=/admin/
  [wsgi:error] [pid 26646:tid 140557972109056] [client xx.xx.xxx.xx:57664] error: [Errno 111] Connection refused, referer: ***.com/admin/login/?next=/admin/
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code># Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  import os
  from os import path
  import socket
  from os.path import dirname
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  ROOT_PATH = os.path.dirname(__file__)
  PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'x'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  if socket.gethostname().startswith('x'):
      DEBUG = TEMPLATE_DEBUG = True
  else:
      DEBUG = TEMPLATE_DEBUG = False
  
  ALLOWED_HOSTS = [
      '.accountedge.com',
      'accountedge.com',
      'localhost',
      '162.209.1.124',
      '162.209.4.135',
  ]
  
  
  # Application definition
  
  INSTALLED_APPS = (
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'geoip',
      'localflavor',
      'partners',
  )
  
  MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  )
  
  ROOT_URLCONF = 'accountedge.urls'
  
  WSGI_APPLICATION = 'accountedge.wsgi.application'
  
  TEMPLATE_DIRS = (
      os.path.join(BASE_DIR, 'accountedge/templates'),
  )
  
  # Database
  # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  
  ADMINS = (
      ('ed', 'x'),
  )
  
  # Internationalization
  # https://docs.djangoproject.com/en/1.7/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'America/New_York'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.7/howto/static-files/
  
  STATIC_URL = '/static/'
  
  STATIC_ROOT = path.join(PROJECT_ROOT, 'static-root/')
  
  ## local
  if socket.gethostname().startswith('x'):
      STATIC_URL = '/static/'
  ## staging: rackspace
  elif socket.gethostname() == 'rerun-mktg':
      STATIC_URL = 'http://x/accountedge/staging/rackspace/static/'
  ## PRODUCTION
  else:
      STATIC_URL = 'http://x/accountedge/static/'
  
  # Additional locations of static files
  STATICFILES_DIRS = (
      ('', path.join(PROJECT_ROOT,'static')),
  )
  
  TEMPLATE_CONTEXT_PROCESSORS = (
      'django.contrib.auth.context_processors.auth',
      'django.core.context_processors.debug',
      'django.core.context_processors.i18n',
      'django.core.context_processors.media',
      'django.core.context_processors.static',
      'django.core.context_processors.tz',
      'django.contrib.messages.context_processors.messages',
      'geoip.context.maxmind',
  )
  
  TEMPLATE_LOADERS = (
      'django.template.loaders.filesystem.Loader',
      'django.template.loaders.app_directories.Loader',
  #     'django.template.loaders.eggs.load_template_source',
  )
  </code></pre>