我的django视图正在我的模板中传递:
context={'material':material_id,'inventory_list':inventory,'now_time':datetime.now()
在我的material对象中,我有一个字段,用于更新每次新保存:
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()}
)