<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.now{
color: red;
}
h3{
text-align: center;
}
</style>
</head>
<body>
<h3>当前时间:<span class="now">{{ show_time }}</span></h3>
</body>
</html>
from django.shortcuts import render
# Create your views here.
from django.shortcuts import HttpResponse
def get_timer(request):
import datetime
now = datetime.datetime.now().strftime("%Y-%m-%d-%X")
#返回字符串
#return HttpResponse(now)
#返回界面
##render函数方法
return render(request,"app01/timer.html", {"show_time": now})
##open方法
'''with open("templates/app01/timer.html",encoding="utf8") as f:
data = f.read()
print(data)
return HttpResponse(data)'''