title: Key Error with form - DJANGO
body: <p>I have a project in django and I am creating a simple form that will allow a user to create a simple profile that asks for name and date of birth and location. I am getting a key error with the date of birth section and I dont know exactly why.</p>
  
  <p>I am trying to collect data and store it to then later added it to a database record.</p>
  
  <p>Here is the views file:</p>
  
  <pre><code>cd = form.cleaned_data
  first_name = cd['first_name']
  last_name = cd['last_name']
  dob_month = cd['dob_month']
  dob_day = ['dob_day']
  dob_year = ['dob_year']
  city = cd['city']
  state = cd['state']
  phone = cd['phone']
  privacy = cd['privacy']
  </code></pre>
  
  <p>Here is the models file:</p>
  
  <pre><code>user = models.ForeignKey(User, on_delete=models.CASCADE)  # server
  first_name = models.CharField(max_length=25, default='first')
  last_name = models.CharField(max_length=25, default='last')
  dob_month = models.IntegerField(default=0)
  dob_day = models.IntegerField(default=0)
  dob_year = models.IntegerField(default=0)
  city = models.CharField(max_length=45)  # user
  state = models.CharField(max_length=25, default='state')
  phone = models.BigIntegerField(default=0)  # user
  privacy = models.SmallIntegerField(default=1)  # user
  created = models.DateTimeField(auto_now_add=True)  # server
  </code></pre>
  
  <p>here is the forms file:</p>
  
  <pre><code>class ProfileForm(forms.ModelForm):
      split_choices = (('1', 'public'),
                       ('2', 'private'))
      privacy = forms.TypedChoiceField(
          choices=split_choices, widget=forms.RadioSelect, coerce=int
      )
      dob = forms.DateField(widget=extras.SelectDateWidget)
      class Meta:
          model = Profile
          fields = ['first_name', 'last_name', 'dob', 'city', 'state', 'phone', 'privacy']
  </code></pre>
  
  <p>and finally, here is the error that I am getting:</p>
  
  <pre><code>    KeyError at /setup_profile/
      'dob_month'
      Request Method: POST
      Request URL:    http://127.0.0.1:8000/setup_profile/
      Django Version: 1.8.6
      Exception Type: KeyError
      Exception Value:    
      'dob_month'
      Exception Location: C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in profile_setup, line 292
  first_name  'omar'
  last_name   'jandali'
  dob_month   '1'
  dob_day     '23'
  dob_year    '2024'
  city        'riverside'
  state       'ca'
  phone       '9515343666'
  privacy     '1'
  submit      'submit'
  </code></pre>
  
  <p>UPDATED:</p>
  
  <p>here is the views.py file but the issue is with the cd['dobv_month'], but i have no idea why the error is coming from there. </p>
  
  <pre><code>def profile_setup(request):
      if 'username' not in request.session:
          return redirect('login')
      else:
          # the following is just going to grab the currently logged in user and
          # save the profile information to the appropriate user
          username = request.session['username']
          currentUser = User.objects.get(username = username)
          # the following is the provessing for the form where the user entered
          # the profile informaiton
          if request.method == 'POST':
              form = ProfileForm(request.POST)
              if form.is_valid():
                  cd = form.cleaned_data
                  first_name = cd['first_name']
                  last_name = cd['last_name']
                  dob_month = cd['dob_month']
                  dob_day = ['dob_day']
                  dob_year = ['dob_year']
                  city = cd['city']
                  state = cd['state']
                  phone = cd['phone']
                  privacy = cd['privacy']
                  # this is the new record that is going to be created and saved
                  new_profile = Profile.objects.create(
                      user = currentUser,
                      first_name = first_name,
                      last_name = last_name,
                      dob_month = dob_month,
                      dob_day = dob_day,
                      dob_year = dob_year,
                      city = city,
                      state = state,
                      phone = phone,
                      privacy = privacy,
                  )
                  return redirect('home_page')
          else:
              # this is what is going to be saved into the html file and used to
              # render the file
              form = ProfileForm()
              message = 'fill out form below'
              parameters = {
                  'form':form,
                  'currentUser':currentUser,
                  'message':message,
              }
              return render(request, 'tabs/profile_setup.html', parameters)
  </code></pre>