django人性化时间不打印

时间:2018-05-18 10:12:13

标签: django web django-models django-templates

我的django视图在我的模板中传递:

context={'material':material_id,'inventory_list':inventory,'now_time':datetime.now()

在我的材质对象中,我有一个更新每个新保存的字段:

last_update = models.DateTimeField()

我试图在屏幕上打印人性化时间,所以我这样做:

{{now_time | timesince:material.last_update }}

它没有打印任何内容,尽管两个变量分别正确显示:

{{now_time}} {{material.last_update}}
OUTPUT:
May 18, 2018, 11:10 a.m. May 18, 2018, 10:45 a.m.

以下是我的完整观点:

def material_page(request,pk):
try:
    material_id=Material.objects.get(id=pk)
    inventory = InventoryMove.objects.filter(material=material_id).order_by("-date")
    i=0
    for movement in inventory:
        print (inventory[i].date)
        i+=1
except Material.DoesNotExist:
    raise Http404("Material does not exist")
return render(
     request,
    'material_detail.html',
    context={'material':material_id,'inventory_list':inventory,'now_time':datetime.now()}
    )

0 个答案:

没有答案