Django Forms: TimeField Validation

余生颓废 提交于 2019-12-03 12:19:05

You need to use %I to parse the hours when you specify %p. See the first note under the table of directives here: http://docs.python.org/library/time.html#time.strftime.

Got it thanks to Karen's answer: the formatting characters aren't the ones listed for Django's now/ date filters, they're the ones for Python's time.strftime(format[, t]). To accept AM/ PM, you need to switch from %H to %I so the filters now look like:

valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p']

(This message brought to you by open source code. Without it, I'd never have figured it out.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!