django的SelectDateWidget的日期格式 [英] Date format for django's SelectDateWidget

查看:77
本文介绍了django的SelectDateWidget的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SelectDateWidget非常方便,但通常似乎以%Y-%m-%d"格式返回日期.它不需要格式参数,也没有太多文档.任何人都遇到这种情况或有一个想法如何解决它以获取日期输出为另一种格式?有一张票证,#6231 说,有一种修复程序可以使它使用来自以下位置的DATE_FORMAT设置: settings.py(尽管我不明白为什么也不能只给它一个format参数).票证中有一个补丁是从2个月前开始实现的,所以似乎我必须获得django的最新开发版才能使用它,除非有办法将这个补丁应用到我的django安装中? >

SelectDateWidget is very convenient but it normally seems to return dates in the format "%Y-%m-%d". It doesn't take a format parameter and doesn't have much documentation. Anyone run into this or have an idea how to work around it to get the output of the date into another format? There is this ticket, #6231 saying that there's a fix to have it use a DATE_FORMAT setting from settings.py (though I don't see why it can't just be given a format parameter also). There's a patch in the ticket from 2 months ago to implement this, so it seems I would have to get the latest dev version of django to use it, unless there is a way I can apply just this patch to my django install?

推荐答案

DATE_FORMAT与SelectDateWidget一起使用,但是您必须使用不带百分比的格式字符串(如在

DATE_FORMAT works with SelectDateWidget but you have to use format strings without percents (as used in: now template tag) like this:

DATE_FORMAT = 'j N Y'

这篇关于django的SelectDateWidget的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆