title: Why when i logout in django after i updated my data appears this error?
body: <p>i'm new in django and i'm trying to create an application that Admin have CRUD function. My problem is when admin updated other user, and then logged off, log off function worked properly. But, when admin updated him/her self then admin logout, appears this error</p>
  
  <pre><code>KeyError at /simofa/logout/
  'username'
  Request Method: GET
  Request URL:    http://localhost:8000/simofa/logout/
  Django Version: 1.7.4
  Exception Type: KeyError
  Exception Value:    
  'username'
  Exception Location: /usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py in __delitem__, line 56
  Python Executable:  /usr/bin/python
  Python Version: 2.7.6
  Python Path:    
  ['/home/boss/kantor/akun',
   '/usr/lib/python2.7/dist-packages',
   '/usr/lib/python2.7',
   '/usr/lib/python2.7/plat-i386-linux-gnu',
   '/usr/lib/python2.7/lib-tk',
   '/usr/lib/python2.7/lib-old',
   '/usr/lib/python2.7/lib-dynload',
   '/usr/local/lib/python2.7/dist-packages',
   '/usr/lib/python2.7/dist-packages/PILcompat',
   '/usr/lib/python2.7/dist-packages/gtk-2.0',
   '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
   '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
  Server time:    Tue, 10 Mar 2015 02:24:44 +0000
  </code></pre>
  
  <p>This is the traceback:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/simofa/logout/
  
  Django Version: 1.7.4
  Python Version: 2.7.6
  Installed Applications:
  ('django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'simofa',
   'accounts')
  Installed Middleware:
  ('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')
  
  
  Traceback:
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
    111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/boss/kantor/akun/simofa/views.py" in logout
    174.     del request.session['username']
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py" in __delitem__
    56.         del self._session[key]
  
  Exception Type: KeyError at /simofa/logout/
  Exception Value: 'username'
  </code></pre>
  
  <p>This is my views: (update and logout)</p>
  
  <pre><code>def update_user(request, pk, template_name='update_user.html'):
      #cek session
      if 'username' in request.session:
          user = get_object_or_404(User, pk=pk) #ambil id dengan get
          profile = UserProfile.objects.filter(user=user).first()
          user_form = UserForm(data=request.POST, instance=user) #gunakan instance untuk mengambil data yang sudah ada
          profile_form = UserProfileForm(data=request.POST, instance=profile) #gunakan instance untuk mengambil data yang sudah ada
          users = User.objects.all()
          if request.POST:
              if user_form.is_valid() and profile_form.is_valid():
                  user.set_password(user.password) #hashing
                  user.save()
                  profile = profile_form.save(commit=False)
                  profile.user = user
                  profile.save()
                  return redirect('manajemen_user')
          else:
              user_form = UserForm(instance=user)
              profile_form = UserProfileForm(instance=profile)
  
          data = {
                  'user_form': user_form,
                  'profile_form': profile_form,
                  'object_list': users,
          }
          return render(request, template_name, data)
      else:
          return HttpResponseRedirect('/simofa/login')
  
  def logout(request):
      del request.session['username']
      del request.session['password']
      del request.session['hak_akses']
      return HttpResponseRedirect('/simofa/login')
  </code></pre>
  
  <p>I've confused with this error, why when admin update his self then logout it can't work properly? And how to fix it ?</p>
  
  <p>Because i think nothing wrong with my update and logout function. 
  I will very grateful for your input. So, please help me. Thank you very much </p>