【发布时间】:2011-12-04 12:14:51
【问题描述】:
当有些人发布了新的论坛帖子时,我正在尝试做一个简单的通知。这在过去可以工作,但现在由于某种原因它不起作用。我不知道我做了什么来打破它。在我的 index.html 模板中,我做了一个时间比较:
<li class="{% if topic.topic_last_post.post_time > request.user.last_login %}bold notification{% endif %}">...</li>
比较有效。但是,似乎 request.user.last_login 在呈现模板之前已更新。这是我的视图代码。对吗?
class FrontpageView(TemplateView):
template_name = "frontpage/index.html"
def render_to_response(self, context, **response_kwargs):
t = TemplateView.render_to_response(self, context, **response_kwargs)
if self.request.user.is_authenticated():
now = datetime.datetime.now()
self.request.user.last_login = now
self.request.user.save()
return t
【问题讨论】:
标签: django templates time notifications render