Django 1.2:管理表单中的日期不适用于区域设置(I10N=True)
我有一个 Django 1.2 中的应用程序。 语言是可选的(I18N 和区域设置 = True)
当我选择英语时, 。在网站中,管理员工作正常。但是,当我更改为任何其他语言时,日期输入会发生这种情况(西班牙语示例):
正确地,输入接受西班牙语格式 %d/%m/%Y
(即使从日历中选择,日期按预期插入)。但是,当我保存表单并再次加载时,日期以英文形式显示: %Y-%m-%d
真正的问题是,当我加载表单以更改任何其他文本字段时并尝试保存它,但出现错误,告诉我输入有效日期,因此我必须再次写入所有日期或更改网站中的语言才能使用管理员。
我没有在设置中为 DATE_INPUT_FORMATS 指定任何内容,也没有覆盖表单或模型。
我肯定错过了一些东西,但我找不到它。有人能给我提示吗?
I have an application in Django 1.2.
Language is selectable (I18N and Locale = True)
When I select the english lang. in the site, the admin works OK. But when I change to any other language this is what happens with date inputs (spanish example):
Correctly, the input accepts the spanish format %d/%m/%Y
(Even selecting from the calendar, the date inserts as expected). But when I save the form and load it again, the date shows in the english form: %Y-%m-%d
The real problem is that when I load the form to change any other text field and try to save it I get an error telling me to enter a valid date, so I have to write all dates again or change the language in the site to use the admin.
I haven't specified anything for DATE_INPUT_FORMATS in settings nor have I overridden forms or models.
Surely I am missing something but I can't find it. Can anybody give me a hint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其添加到您的设置中应该可以解决您所谓的“真正问题”的部分:
但这是 Django 的问题。我打开了关于该问题的票证,但您应该发表评论,因为您的示例显示它甚至比我想象的更严重的问题(因为事实证明并非所有本地化都接受“通用”和“本地化”日期输入格式)。
更新:我忘记补充一点,您可以将
localize=True
传递给日期小部件,然后它们应该始终以本地化格式显示日期。 此错误报告中有一些如何执行此操作的示例。我刚刚向 django-developers 发布了关于该问题的一条消息邮件列表。
Adding this to your settings should solve the part you call "the real problem":
But it's a problem with Django. I opened a ticket about the issue, but you should comment, because your example shows it is even more serious problem then I thought it was (because as it turned out not all localization accepts both "universal" and "localized" date input formats).
Update: I forgot to add that you can pass
localize=True
to your date widgets, and they are supposed to then always display dates in localized format. There are some examples of how to do this in this bug report.I just posted a message about the issue to django-developers mailing list.