Python 入門指南

web_demo/views.py

本書已有新版,請參考 Python 入門指南 5.00 - 目錄

from datetime import datetime

from django.shortcuts import render

def now(request):
  now = datetime.now()
  h = str(now.hour)
  if len(h) == 1:
    h = "0" + h
  m = str(now.minute)
  if len(m) == 1:
    m = "0" + m
  s = str(now.second)
  if len(s) == 1:
    s = "0" + s
  now_str = h + ":" + m + ":" + s

  return render(request, 'web_demo/home.html', {
    'current_time': now_str,
  })

# 檔名: views.py
# 作者: Kaiching Chang
# 時間: June, 2018

回 Python 入門指南首頁
回 Python 教材首頁
回程式語言教材首頁