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>
CodePudding user response:
You can use date filter in your template like this:
<h5 style="color: #fff">{{ data|date:"H, i, s" }}</h5>
views py:
def contatore(request):
settaggio = Count.objects.get(attivo = True)
context = {'data':settaggio.data}
return render(request, 'count.html', context)
CodePudding user response:
Try this
{{ data |date:"g:i a" }}
