当我使用assert false方法时,我收到错误:
assertionError at /time/plus/2/
No exception supplied
Request Method: GET
Request URL: http://localhost:8000/time/plus/2/
Django Version: 1.4
Exception Type: AssertionError
Exception Location: C:\my\my\views.py in hours_ahead, line 18
这是我的代码:
from django.http import HttpResponse, Http404
import datetime
def hello(request):
return HttpResponse("Hello World")
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>it is now %s.</body></html>" % now
return HttpResponse(html)
def hours_ahead(request, offset):
try:
offset = int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
assert False
html = "<html><body>In %s hours,it will be %s.</body></html>" % (offset, dt)
return HttpResponse(html)
我编写了django part2的明确指南中的代码。但它得到了错误,我无法理解这段代码中的错误。谢谢你的帮助。