title: How do I calculate age using Django with a class-based form, templates and gijgo datepicker?
body: <p>I have read this post and I believe that mine in totally different; <a href="https://stackoverflow.com/questions/17120305/django-datepicker-calculate-age">Django Datepicker calculate age</a></p>
  <p>I am using Django version 4.0.1.  I am making use of the Gijgo datepicker to capture the date of birth of the person registering.  In my base.html template I added this:</p>
  <pre><code>&lt;script src=&quot;https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
  &lt;script&gt;$('.dateinput').datepicker({ format: 'yyyy-mm-dd' });&lt;/script&gt;
  </code></pre>
  <p>In my register.html template I extends the base template.  The form in the register template use a POST method. The code is:</p>
  <pre><code>&lt;form method=&quot;POST&quot;&gt;
  {% csrf_token %}
  {{ form|crispy }}
  </code></pre>
  <p>With a submit button.  The form I use is a class based form in my forms.py file.  The code for that looks like this:</p>
  <pre><code>from django import forms
  from django.contrib.auth.forms import UserCreationForm
  from datetime import date
  
  selection = [
  ('yes', 'Yes'),
  ('no', 'No')
  ]
  
  class StudentApplicationForm(UserCreationForm):
  email = forms.EmailField()
  first_name = forms.CharField(max_length=70)
  last_name = forms.CharField(max_length=150)
  date_of_birth = forms.DateField()
  previous_experience = forms.CharField(widget=forms.RadioSelect(choices=selection))
  terms_and_conditions = forms.CharField(widget=forms.CheckboxInput())
  
  class Meta:
      model = User
      fields = [
          'first_name',
          'last_name',
          'date_of_birth',
          'terms_and_conditions',
          'previous_experience',
          'username',
          'email',
          'password1',
          'password2',
      ]
  
  
  def clean_email(self):
      email = self.cleaned_data.get('email')
      email_count = User.objects.filter(email=email).count()
  
      if email_count &gt; 0:
          raise forms.ValidationError('This email is already in use.  Please select a different email!')
      return email
  
  def calc_age(self):
      dob = self.cleaned_data.get('date_of_birth')
      raise forms.ValidationError(int(dob))
  
      return dob
  </code></pre>
  <p>The email function works.  For now, I just want to see what I get from the date_of_birth input, but I don't get anything on my screen.  See the image below.</p>
  <p><a href="https://i.stack.imgur.com/JcNzd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JcNzd.jpg" alt="enter image description here" /></a></p>
  <p>Any help would be greatly appreciated.</p>