title: Django admin site cannot connect to the database - using the wrong mongodb engine
body: <p>I've had the admin site working for my django app before but now I just can't find out what is the problem.</p>
  
  <p>On <code>settings.py</code> I have the mongodb database configuration:</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django_mongodb_engine', 
          'NAME': 'myapp', 
          'USER': 'username',
          'PASSWORD': '********'
          'HOST': 'myserver.com',          
          'PORT': '27157',
          'SUPPORTS_TRANSACTIONS': False,
      }
  }
  </code></pre>
  
  <p>I know those settings are correct because I have already some views reading information from the database and displaying it. So I know for a fact that my application can connect to the mongodb database.</p>
  
  <p>I've <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/admin/" rel="nofollow">configured</a> urls.py, admin.py and settings.py to enable the admin site (and I had it working at some point before). However now when I try to access it I just get:</p>
  
  <pre><code>Traceback:
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
    111.                         response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py" in wrapper
    214.                 return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py" in _wrapped_view
    93.                     response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
    79.         response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py" in inner
    195.             if not self.has_permission(request):
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py" in has_permission
    148.         return request.user.is_active and request.user.is_staff
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/middleware.py" in __get__
    9.             request._cached_user = get_user(request)
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/__init__.py" in get_user
    107.         user_id = request.session[SESSION_KEY]
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/sessions/backends/base.py" in __getitem__
    47.         return self._session[key]
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/sessions/backends/base.py" in _get_session
    195.                 self._session_cache = self.load()
  File "/usr/local/lib/python2.6/dist-packages/mongoengine/django/sessions.py" in load
    26.             s = MongoSession.objects(session_key=self.session_key,
  File "/usr/local/lib/python2.6/dist-packages/mongoengine/queryset.py" in __get__
    1151.         db = _get_db()
  File "/usr/local/lib/python2.6/dist-packages/mongoengine/connection.py" in _get_db
    41.         _connection[identity] = _get_connection(reconnect=reconnect)
  File "/usr/local/lib/python2.6/dist-packages/mongoengine/connection.py" in _get_connection
    33.             raise ConnectionError('Cannot connect to the database')
  
  Exception Type: ConnectionError at /admin/
  Exception Value: Cannot connect to the database
  </code></pre>
  
  <p>I've introduced some debug information in the <code>mongoengine/connection.py</code> and I can see that the connection settings that are used to connect to the database are:</p>
  
  <pre><code>{'host': 'localhost', 'port': 27017}
  </code></pre>
  
  <p>which means that it is using the default connection settings instead of the  settings provided by me on <code>settings.py</code>. Any idea of what could be causing this? Why aren't the database settings being passed to the admin site? Maybe I forgot to do something in the admin configuration?</p>
  
  <p><strong>EDIT:</strong><br>
  I have followed <a href="http://django-mongodb.org/topics/setup.html" rel="nofollow">these instructions</a> to configure my django app to work with the mongodb database. I am using <strong><a href="http://pypi.python.org/pypi/djangotoolbox" rel="nofollow">djangotoolbox</a></strong> and <strong><a href="http://www.allbuttonspressed.com/projects/django-nonrel" rel="nofollow">django-nonrel</a></strong>.</p>
  
  <p>Just now I realized that the mongodb engine that should be used when I set 'ENGINE': 'django_mongodb_engine' is the <a href="https://github.com/django-mongodb-engine/mongodb-engine" rel="nofollow">django-mongodb-engine</a> and not <a href="http://pypi.python.org/pypi/mongoengine/0.4" rel="nofollow">mongoengine</a>. But in the stacktrace I can see that it is using mongoengine. (django-mongodb-engine does not depend on mongoengine) I am guessing that the right one is being used in the views (and that's why it works) but the admin is using mongoengine for some reason?!?!
  If understand correctly my app should not even require mongoengine to work. It is only installed because I was experimenting with it some time before.</p>