django forms dateField fails validation

前端 未结 2 1719
说谎
说谎 2021-01-03 05:40

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() ret

相关标签:
2条回答
  • 2021-01-03 05:52

    input formats in DateField must be list or tuple https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.DateField.input_formats

    0 讨论(0)
  • 2021-01-03 05:53

    With Django 1.6 and up you can use the localized_fields in your form's Meta or localize=True in your form. See https://docs.djangoproject.com/en/1.9/topics/i18n/formatting/#format-localization.

    When using USE_L10N = True, Django will use the formats.py file for your locale (part of LANGUAGE_CODE).

    You can end up with something DRY like this (as the fields specified in models.py do not need to be repeated in forms.py):

    class SomeForm(forms.Form):
    
        class Meta:
            model = SomeModel
            fields = ('first_name', 'dob',)
            localized_fields = ('dob',)
    
    0 讨论(0)
提交回复
热议问题