title: Django KeyError at /register/
body: <p>I have a registration that let users register and i'm having difficulty fixing it.</p>
  
  <p>The problem is when a user submits a single field instead of the whole form for example an email . I get this error</p>
  
  <pre><code>KeyError at /register/
  
  password
  Request Method:     POST
  Request URL:    http://127.0.0.1:8000/register/
  File "C:\Python26\Lib\site-packages\django\forms\forms.py" in _get_errors
    115.             self.full_clean()
  File "C:\Python26\Lib\site-packages\django\forms\forms.py" in full_clean
    271.         self._clean_form()
  File "C:\Python26\Lib\site-packages\django\forms\forms.py" in _clean_form
    299.             self.cleaned_data = self.clean()
  File "C:\o\17\mysite\pet\forms.py" in clean
    31.       if self.cleaned_data['password'] != self.cleaned_data['password1']:
  
  Exception Type: KeyError at /register/
  Exception Value: password
  </code></pre>
  
  <p>I tried to fix this solution using if . If user has a submitted a username or any other required field , process the form otherwise redisplay the original form.</p>
  
  <p>but I still get the same error.</p>
  
  <p>This is my edited views.py <strong><em>(at the bottom of the page is my original RegistrationForm)</em></strong></p>
  
  <pre><code>def PetRegistration(request):   
      if request.user.is_authenticated():
          return HttpResponseRedirect(reverse('world:HappyLand'))
  
      if request.method =='POST':
          form = UserRegistration(request.POST)
      if form.is_valid():
          username = form.cleaned_data['username']
          if username:
              email=form.cleaned_data['email']
              if email:
                  password=form.cleaned_data['password']
                  if password:
                      user = User.objects.create_user(
              username=form.cleaned_data['username'], 
              email=form.cleaned_data['email'], 
              password=form.cleaned_data['password']
              )
                      user.is_active = True
                      user.first_name = form.cleaned_data['name']
                      user.save()
  
                      person = authenticate(
              username=form.cleaned_data['username'], 
              password=form.cleaned_data['password']
              )
  
                      Person.objects.create(user_id=user.id, 
                      name=form.cleaned_data['name'],birthday=form.cleaned_data['birthday'])
  
                      login(request, person)
                      return HttpResponseRedirect(reverse('world:HappyLand'))
  
  return render(request, 'register.html', {'form': UserRegistration()})
  </code></pre>
  
  <p>How can I fix this error and also how could I display an error message on the other fields that the user didn't fill out like "Error Missing Field , Please Fill this Field".</p>
  
  <pre><code>def PetRegistration(request):   
  if request.user.is_authenticated():
      return HttpResponseRedirect(reverse('world:HappyLand'))
  
  if request.method =='POST':
      form = UserRegistration(request.POST)
      if form.is_valid():
          user = User.objects.create_user(
              username=form.cleaned_data['username'], 
              email=form.cleaned_data['email'], 
              password=form.cleaned_data['password']
              )
          user.is_active = True
          user.first_name = form.cleaned_data['name']
          user.save()
  
          person = authenticate(
              username=form.cleaned_data['username'], 
              password=form.cleaned_data['password']
              )
  
          Person.objects.create(user_id=user.id, 
              name=form.cleaned_data['name'],birthday=form.cleaned_data['birthday'])
  
          login(request, person)
          return HttpResponseRedirect(reverse('world:HappyLand'))
  
  return render(request, 'register.html', {'form': UserRegistration()})
  </code></pre>
  
  <p>My forms.py</p>
  
  <pre><code>class UserRegistration(forms.Form):
      username = forms.CharField()
      name = forms.CharField()
      email = forms.EmailField()
      birthday = forms.DateField(widget=extras.SelectDateWidget(years=range(1950, 2012)))
  
      password = forms.CharField(
          widget=forms.PasswordInput(render_value=False)
          )
      password1 = forms.CharField(
          label=(u'Verify Password'), 
          widget = forms.PasswordInput(render_value=False)
          )
  
      def clean_username(self):
          username = self.cleaned_data['username']
          try:
              User.objects.get(username=username)
          except User.DoesNotExist:
              return username
          raise forms.ValidationError(
              "That user is already taken , please select another ")
  
      def clean(self):
          if self.cleaned_data['password'] != self.cleaned_data['password1']:
              raise forms.ValidationError("The password does not match ")
          return self.cleaned_data
  </code></pre>
  
  <p>My models.py</p>
  
  <pre><code>class Person(models.Model):
      user = models.ForeignKey(User)
      name = models.CharField(max_length=100, blank=True)
      birthday = models.DateField(blank=True,null=True)
      def __unicode__(self):
          return self.name
  </code></pre>