カウントダウンのチュートリアルをここからクラスベースのビューに変換しようとしましたが、何が欠けているのかわかりません。
ビュー.py
class TimeDifferenceView(TemplateView):
delta = datetime(2022, 12, 1, tzinfo=timezone.utc) - timezone.now()
template_name = 'base.html'
days = delta.days
seconds = delta.seconds % 60
minutes = (delta.seconds //60) % 60
hours = delta.seconds // 3600
def get_context_data(self,*args, **kwargs):
# Call the base implementation first to get the context
context = super(TimeDifferenceView, self).get_context_data(*args, **kwargs)
# Create any data and add it to the context.
context['days'] = self.days
context['seconds'] = self.seconds
context['minutes'] = self.minutes
context['hours'] = self.hours
return context
base.html
<div
id= "time"
class="d-flex justify-content-between"
hx-get="{% url 'time_difference' %}"
hx-trigger="every 1s"
hx-select="#time"
hx-swap="outerHTML"
>
<div>
<h5>Days</h5>
<p> {{days}} </p>
</div>
<div>
<h5>Hours</h5>
<p> {{hours}} </p>
</div>
<div>
<h5>Minutes</h5>
<p> {{minutes}} </p>
</div>
<div>
<h5>Seconds</h5>
<p> {{seconds}} </p>
</div>
</div>