title: Django custom login page
body: <p>I have a custom Django login page. I want to throw an exception when username or password fields are empty. How can I do that?</p>
  
  <p>My view.py log in method :</p>
  
  <pre><code>def user_login(request):
      context = RequestContext(request)
      if request.method == 'POST':
          # Gather the username and password provided by the user.
          # This information is obtained from the login form.
          username = request.POST['username']
          password = request.POST['password']
          user = authenticate(username=username, password=password)
          print("auth",str(authenticate(username=username, password=password)))
  
          if user:
              # Is the account active? It could have been disabled.
              if user.is_active:
                  login(request, user)
                  return HttpResponseRedirect('/')
          else:
              return HttpResponse("xxx.")
      else:
          # Bad login details were provided. So we can't log the user in.
          print ("Invalid login details: {0}, {1}".format(username, password))
          return HttpResponse("Invalid login details supplied.")
      else:
          return render_to_response('user/profile.html', {}, context)
  </code></pre>
  
  <p>I tried this and it didn't work:
  This is forms.py</p>
  
  <pre><code>def clean_username(self):
      username = self.cleaned_data.get('username')
      if not username:
          raise forms.ValidationError('username does not exist.')
  </code></pre>