这段代码无法执行:
def hours_ahead(request, offset):
try:
offset = int(offset)
except ValueError:
raise Http404()
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt)
return HttpResponse(html)
它返回以下错误消息:
hours_ahead() missing 1 required positional argument: 'offset'
我安装了Python 3.3。我在这里找不到任何东西?
答案 0 :(得分:6)
我改变了:
url(r'^time/plus/\d+/$', hours_ahead)
为:
url(r'^time/plus/(\d+)/$', hours_ahead)
显然它解决了我的问题。