title: Unable log in to the django admin page with a valid username and password
body: <p>I can’t log in to the django admin page. When I enter a valid username and password, it just brings up the login page again, with no error messages</p>
  
  <p>This question is in the <a href="https://docs.djangoproject.com/en/dev/faq/admin/#i-can-t-log-in-when-i-enter-a-valid-username-and-password-it-just-brings-up-the-login-page-again-with-no-error-messages" rel="noreferrer">django FAQ</a>, but I've gone over the answers there and still can't get past the initial login screen.</p>
  
  <p>I'm using django 1.4 on ubuntu 12.04 with apache2 and modwsgi.</p>
  
  <p>I've confirmed that I'm registering the admin in the <code>admin.py</code> file, made sure to syncdb after adding <code>INSTALLED_APPS</code>.
  When I enter the wrong password I <em>DO</em> get an error, so my admin user is being authenticated, just not proceeding to the admin page.</p>
  
  <p>I've tried both setting <code>SESSION_COOKIE_DOMAIN</code> to the machine's IP and None.  (Confirmed that the cookie domain shows as the machine's IP in chrome)</p>
  
  <p>Also, checked that the user authenticates via the shell:</p>
  
  <pre><code>&gt;&gt;&gt; from django.contrib.auth import authenticate
  &gt;&gt;&gt; u = authenticate(username="user", password="pass")
  &gt;&gt;&gt; u.is_staff
  True
  &gt;&gt;&gt; u.is_superuser
  True
  &gt;&gt;&gt; u.is_active 
  True
  </code></pre>
  
  <p>Attempted login using IE8 and chrome canary, both results in the same return to the login screen.</p>
  
  <p>Is there something else I'm missing????</p>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>...
  MIDDLEWARE_CLASSES = (
      'django.middleware.gzip.GZipMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.middleware.transaction.TransactionMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
  )
  AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
  INSTALLED_APPS = (
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.sites',
      'django.contrib.messages',
      'django.contrib.admin',    
      'django.contrib.staticfiles',
      'django.contrib.gis',
      'myapp.main',
  )
  
  SESSION_EXPIRE_AT_BROWSER_CLOSE = True
  SESSION_SAVE_EVERY_REQUEST = True
  SESSION_COOKIE_AGE = 86400 # sec
  SESSION_COOKIE_DOMAIN = None
  SESSION_COOKIE_NAME = 'DSESSIONID'
  SESSION_COOKIE_SECURE = False
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>from django.conf.urls.defaults import * #@UnusedWildImport
  from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  from django.contrib import admin
  
  admin.autodiscover()
  
  urlpatterns = patterns('',
      (r'^bin/', include('myproject.main.urls')),    
      (r'^layer/r(?P&lt;layer_id&gt;\d+)/$', "myproject.layer.views.get_result_layer"),
      (r'^layer/b(?P&lt;layer_id&gt;\d+)/$', "myproject.layer.views.get_baseline_layer"),
      (r'^layer/c(?P&lt;layer_id&gt;\d+)/$', "myproject.layer.views.get_candidate_layer"),    
      (r'^layers/$', "myproject.layer.views.get_layer_definitions"),
      (r'^js/mapui.js$', "myproject.layer.views.view_mapjs"),
      (r'^tilestache/config/$', "myproject.layer.views.get_tilestache_cfg"),
      (r'^admin/', include(admin.site.urls)),  
      (r'^sites/', include("myproject.sites.urls")),  
      (r'^$', "myproject.layer.views.view_map"),
  )
  
  
  urlpatterns += staticfiles_urlpatterns()
  </code></pre>
  
  <p>Apache Version:</p>
  
  <pre><code>Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured
  </code></pre>
  
  <p>Apache apache2/sites-available/default:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerAdmin ironman@localhost
          DocumentRoot /var/www/bin
          LogLevel warn
          WSGIDaemonProcess lbs processes=2 maximum-requests=500 threads=1
          WSGIProcessGroup lbs
          WSGIScriptAlias / /var/www/bin/apache/django.wsgi
          Alias /static /var/www/lbs/static/
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:8080&gt;
          ServerAdmin ironman@localhost
          DocumentRoot /var/www/bin
          LogLevel warn
          WSGIDaemonProcess tilestache processes=2 maximum-requests=500 threads=1
          WSGIProcessGroup tilestache
          WSGIScriptAlias / /var/www/bin/tileserver/tilestache.wsgi
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The admin page does proceed when using the development server via <code>runserver</code> so it seems like a wsgi/apache issue.  Still haven't figured it out yet.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>The problem was that I had the settings file <code>SESSION_ENGINE</code> value set to <code>'django.contrib.sessions.backends.cache'</code> <em>without</em> having the <code>CACHE_BACKEND</code> properly configured. </p>
  
  <p>I've changed the SESSION_ENGINE to <code>'django.contrib.sessions.backends.db'</code> which resolved the issue.</p>