就像我想让段落在星期一一样。星期二,星期三和整个星期的另一段。请帮助给我建议去获取信息的地方!谢谢。
答案 0 :(得分:2)
可以基于星期几进行动态查看,例如:
from django.utils import timezone
def my_view(request):
weekday = timezone.now().weekday()
if weekday == 0:
paragraph = "Happy Monday!"
elif weekday == 1:
paragraph = "Happy Tuesday!"
...
return render(request, 'my_template.html', {'paragraph': paragraph}
您还可以将段落存储在模型中,并通过查询访问它们。
答案 1 :(得分:1)
我没有按照您的意思说“查看”。这与您要寻找的东西接近吗?
>>> import datetime
>>> datetime.datetime.today().weekday()
4
>>> view = ["Monday Message", "Tuesday Message", "Wednesday Message", "Thursday Message",
"Friday Message", "Saturday Message", "Sunday Message", "Week Message"]
>>> print("Today's View: {}".format(view[datetime.datetime.today().weekday()]))
Today's View: Friday Message
答案 2 :(得分:0)