Django:如何格式化DateField的日期表示? [英] Django: How to format a DateField's date representation?
问题描述
2009-10-03
如何格式化,使其如下所示:
03.10.2009
我发现了一个这样的窗口小部件,但验证不允许我输入的值。
要显示正确格式的初始字段值,请使用 DateInput
小部件。要自定义验证,请使用 input_formats
关键字参数 DateField
。
为什么你需要格式
和 input_formats
?
格式
- 将显示此字段的初始值的格式。请参阅 here 。
input_formats
- 用于尝试将字符串转换为有效的 datetime.date 对象的格式列表。请参阅此处。
I have a form with a DateField. The existing date value is formatted to render like this:
2009-10-03
How can I format that so that it look like this:
03.10.2009
I found a widget which renders it like this, but validation doesn't allow the values I enter then.
To display initial field value properly formatted, use DateInput
widget. To customize validation, use input_formats
keyword argument of DateField
.
Why do you need both format
and input_formats
?
format
- The format in which this field’s initial value will be displayed. See here.
input_formats
- A list of formats used to attempt to convert a string to a valid datetime.date object. See here.
这篇关于Django:如何格式化DateField的日期表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!