【问题标题】:django time display by using timesince使用timesince显示django时间
【发布时间】:2020-10-14 10:37:46
【问题描述】:

从那时起,我一直在使用 Django 模板过滤器标签。 它显示良好的时间大于一分钟。但是当不到一分钟它显示 0 minutes ago 我希望它在几秒钟内完成

这是我的代码

<p>{{ article.article_published_date| timesince | upto :',' }} ago</p>

我需要输出 20 秒前 有什么方法可以显示
现在使用的模板标签是

from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()

@register.filter
@stringfilter
def upto(value, delimiter=None):
    return (value.split(delimiter)[0])
upto.is_safe = True


任何帮助将不胜感激 提前致谢

【问题讨论】:

    标签: python python-3.x django django-templates django-timezone


    【解决方案1】:

    您必须将自己的 template tag 写为 timesince 文档状态

    分钟是使用的最小单位,将返回“0分钟” 对于任何相对于比较点的未来日期。

    timesince的来源

    【讨论】:

    • 我是 django 的新手。你为什么不示例模板标记代码来显示返回秒数
    • 我有一个模板标签,我会提供有问题的
    • 我已经用明确的文档回答了你的问题,因为 timesince 没有秒数也给了你接下来应该看的方法。你应该写它,这是你的工作/爱好,你歪曲了这个网站的用途,看看这个链接(idownvotedbecau.se/noattempt)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2020-04-05
    • 2014-06-08
    • 2015-12-19
    • 1970-01-01
    • 2015-03-25
    相关资源
    最近更新 更多