【发布时间】:2019-08-05 18:30:33
【问题描述】:
我有两个约会:
- 来自数据库的查询集,其中包括日期字段 (1992-11-15) 和 date.today()
这是我的意见.py
def pop(request):
start = randint(0, 2)
finish = randint(2, 5)
current_year = [date.today().year, date.today().year]
context = {
'alluserprofiles': zip(Profile.objects.all()[start:finish],
current_year),
'maleuserprofiles': zip(Profile.objects.filter(gender='male'), current_year),
'femaleuserprofiles': zip(Profile.objects.filter(gender='female'), current_year),
'start': start,
'finish': finish
}
return render(request, 'users/pop.html', context)
这是我的 django 模板
{% for profile, year in alluserprofiles %}
<div class="container fixed-top" id="pop-up">
<div class="card text-center border-light mb-3">
<img class="card-img-top" src="{{ profile.image_prof.url }}" />
<div class="card-body">
<h5> {{ profile.user }} {{ year|sub:profile.birthday.year}}
如何减去它们以获得确切的年龄?我只能管理年份减法。
非常感谢
【问题讨论】: