djangoでユーザープロファイリングフォームを検証しようとしていますが、できません。 forms.dateField()に何か問題があるようです。それは検証しません(すなわちIS_VALID()はfalseを返す。)django forms dateFieldが検証に失敗する
このエントリDateFieldの私のフォームです: date_of_birth = forms.DateField(label=u'date of birth', input_formats='%d/%m/%Y', required=False, widget=forms.DateInput(format = '%d/%m/%Y'))
を私はrequest.POST.get('date_of_birth', '')
が正しい日付(すなわちを返すことに気づいた私は、HTMLフォームで入力した日付。フィールド)。
私もこの機能であることに気づい:
def clean_date_of_birth(self):
date = self.cleaned_data['date_of_birth']
日付オブジェクトは常にNoneです。
私は間違っていますか?
EDIT:
これは私が入力しようとしているものです: 29/07/1974
(7月29日、1974)
これは、(様々な要求を) '提出'
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
の出力でありますこれは私のテンプレートです
<div class="input_area">
<form id="profile_form" method="post" action="/profile/{{ user.username }}/">{% csrf_token %}
{{ form.as_p }}
<input type="submit" id="submit" value="save" class="submitButton idle" style="width:70px" />
</form>
</div>
これは私の見解ですs.py
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'
、最終的にはこれが(現時点でclean_data機能を使用しない)
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)
何日君を入力しようとしていますか? –
入力を教えてください。あなたが持っているフィールド以外のフォームコードを私たちに教えてください。関連するビューコードを表示します。 – Marcin
設定とは何ですか.TIME_ZONE? –