def sample_view(request, *args, **kwargs):
from datetime import date
current_date = date.today()
current_day = int(current_date.day) # force a cast to an int, just to be explicit
return render_to_response("template", {'day_of_the_month': current_day })
有几点需要理解:
因此,在我看来,最简单的方法是:
因此,我们的观点如下:
在我们的模板中,我们将:
^{pr2}$这会将一些内容暴露到模板中,出于安全原因,您可能会根据日期隐藏这些内容。永远不要在基于if/then检查的模板中隐藏安全内容。
如果您需要做额外的检查,您可以只传入},而不是在那天专门传递。它将不那么明确,但更通用和灵活。在
current_date
,然后对照数字10检查{相关问题 更多 >
编程相关推荐