1.在视图文件viewpy中:
from django.http import HttpResponse
import time
def birthday(request, month, day):
month = int(month)
day = int(day)
d = time.localtime(
time.mktime(
time.struct_time((2019, month, day, 0, 0, 0, 0, 0, 0))
)
).tm_yday
return HttpResponse("<p style='color:orange;font-size:30px;'>生日快乐!<br>你的生日是%s月%s日,是一年中的第%s天</p>" % (month, day, d))
2.在路由文件urls.py文件中:
3.启动服务器
4.在浏览器上测试: