'datetimefield only show time in html template
I have a datetime field but in the html code I would like to show only the time, how can I do? I tried {{ data|time }}, {{ value|time:"H:i" }} but nothing
views
from django.shortcuts import render
from .models import Count
import datetime
# Create your views here.
def contatore(request):
settaggio = Count.objects.get(attivo = True)
data = settaggio.data.strftime("%m %d, %Y %H:%M:%S")
context = {'data':data}
return render(request, 'count.html', context)
models
class Count(models.Model):
data = models.DateTimeField()
html
<h5 style="color: #fff">{{ data }}</h5>
Solution 1:[1]
Try this
{{ data |date:"g:i a" }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user8193706 |