Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango forms dateField fails validation
    primarykey
    data
    text
    <p>I am trying to validate a User Profiling form in django and I can't. It seems that there is something wrong with forms.dateField(). It does not validate (ie. is_valid() return false)</p> <p>this is my forms dateField entry: <code>date_of_birth = forms.DateField(label=u'date of birth', input_formats='%d/%m/%Y', required=False, widget=forms.DateInput(format = '%d/%m/%Y'))</code></p> <p>I noticed that <code>request.POST.get('date_of_birth', '')</code> returns the correct date (ie. the date I have typed in the html form field). </p> <p>I also noticed that in this function:</p> <pre><code>def clean_date_of_birth(self): date = self.cleaned_data['date_of_birth'] </code></pre> <p>date object is always None. </p> <p>What am I doing wrong? </p> <p>EDIT: </p> <p>This is what I am trying to enter: <code>29/07/1974</code> (July 29th, 1974)</p> <p>This is the output of 'submit' (various requests)</p> <pre><code>29/07/1974 profile form is *NOT* valid [23/Feb/2012 12:16:27] "POST /profile/chris/ HTTP/1.1" 200 16289 29/7/1974 profile form is *NOT* valid [23/Feb/2012 12:16:33] "POST /profile/chris/ HTTP/1.1" 200 16289 1974-07-29 profile form is *NOT* valid [23/Feb/2012 12:18:15] "POST /profile/chris/ HTTP/1.1" 200 16289 </code></pre> <p>This is my template</p> <pre><code> &lt;div class="input_area"&gt; &lt;form id="profile_form" method="post" action="/profile/{{ user.username }}/"&gt;{% csrf_token %} {{ form.as_p }} &lt;input type="submit" id="submit" value="save" class="submitButton idle" style="width:70px" /&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>this is my views.py</p> <pre><code>def profile(request, username): form = ProfileForm(request.POST) print request.POST.get('date_of_birth', 'None') try: user = User.objects.get(username=username) except User.DoesNotExist: raise Http404(u'User not Found') if form.is_valid(): print 'profile form is valid' else: print 'profile form is *NOT* valid' </code></pre> <p>and finally this is my forms.py (do not use clean_data functions at the moment)</p> <pre><code>class ProfileForm(forms.Form): tz = [] timezones = Timezone.objects.all() for timezone in timezones: val = str(timezone.hour) v = val.split(':') tuple = (timezone.id, '('+timezone.sign+''+v[0]+':'+v[1]+') '+timezone.name) tz.append(tuple) sex = [('male','male'),('female', 'female'),('unknown', 'prefer not to say')] real_name = forms.CharField(label=u'real name', widget=forms.TextInput, required=False) date_of_birth = forms.DateField(label=u'date of birth', input_formats='%d/%m/%Y', required=False, widget=forms.DateInput(format = '%d/%m/%Y')) pp_email = forms.EmailField(label=u'Paypal Email', widget=forms.TextInput, required=False) gender = forms.ChoiceField(label=u'sex', choices=sex, widget=forms.Select(), required=False) timezone = forms.ChoiceField(label=u'time zone', choices=tz, widget=forms.Select()) address = forms.CharField(label=u'street address', widget=forms.Textarea, required=False) postal = forms.CharField(label=u'postal code', widget=forms.TextInput, required=False) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload