【发布时间】:2013-09-04 20:36:10
【问题描述】:
这段代码无法执行:
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。我在这里有什么遗漏吗?
【问题讨论】:
-
这个方法是怎么调用的?
offset参数没有被传递。 -
你是怎么调用函数的?发布完整的回溯。
-
这是 Django 视图吗?什么是 URL 路由配置?
-
感谢您的回复,您提到了 url 配置,我可以看到我的正则表达式有问题:
url(r'^time/plus/\d+/$', hours_ahead), -
试试这个:url(r'^time/plus/(\d+)/$', hours_ahead)
标签: python django python-3.x offset