我只想从模型中检索星期值以查看并将其传递给字典。我在做什么错了?
模型
import datetime
from datetime import date
from django.db import models
class WeekNumber(models.Model):
"""Week number"""
objects = models.Manager()
@staticmethod
def number_of_week():
week = date.today().strftime("%U")
return week
查看
from django.views import View
from django.shortcuts import render
from .models import WeekNumber
class WeekNumbers(View):
model = WeekNumber
template_name = 'week_number'
def get(self, request):
week = WeekNumber.objects.get()
context = {'week': week}
return render(request, 'week_number.html', context)
模板
<tr>
<td>Week {{ week }}</td>
</tr>
我在浏览器中
Week WeekNumber object (1)
非常感谢!