Django-扩展日期模板过滤器 [英] Django - extend date template filter

查看:62
本文介绍了Django-扩展日期模板过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在我的设置中定义一个像 LONG_DATETIME_FORMAT ='D d F Y H:i'这样的变量,并在如下模板中使用它: {{my_date | date:"LONG_DATETIME_FORMAT"}} ?可以在不覆盖默认 date 过滤器的情况下完成此操作吗?还是应该编写自定义过滤器?

I am wondering if I can just define a variable like LONG_DATETIME_FORMAT = 'D d F Y H:i' in my settings and use it in template like: {{ my_date|date:"LONG_DATETIME_FORMAT" }}? Can this be done without overwritting default date filter? Or should I write custom filter?

推荐答案

来自

传递的格式可以是预定义的格式之一, DATE_FORMAT DATETIME_FORMAT SHORT_DATE_FORMAT SHORT_DATETIME_FORMAT 使用上表所示格式说明符的自定义格式.请注意,预定义的格式可能会根据当前的语言环境而有所不同.

The format passed can be one of the predefined ones DATE_FORMAT, DATETIME_FORMAT, SHORT_DATE_FORMAT or SHORT_DATETIME_FORMAT, or a custom format that uses the format specifiers shown in the table above. Note that predefined formats may vary depending on the current locale.

请随时在设置中进行设置

So feel free to set any of them in the settings

DATETIME_FORMAT = 'D d F Y H:i'

{{ my_date|date:"DATETIME_FORMAT" }}

这篇关于Django-扩展日期模板过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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