1

最近我一直在尝试学习 WebPy,当尝试在教程 ( http://webpy.org/docs/0.3/tutorial ) 中使用模板时,我在尝试访问页面时遇到了这个错误。

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 239, in process
return self.handle()

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 230, in handle
return self._delegate(fn, self.fvars, args)

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 420, in _delegate
return handle_class(cls)

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 396, in handle_class
return tocall(*args)

File "/Users/clement/Desktop/#Minecraft/index2.py", line 14, in GET
return render.index(name)

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/template.py", line 1017, in __getattr__
t = self._template(name)

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/template.py", line 1014, in _template
return self._load_template(name)

File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/template.py", line 1001, in _load_template
raise AttributeError, "No template named " + name

AttributeError: No template named index

我已经在 SOF 上查看了这个问题,但我无法让它在我的情况下工作。我花了大约 4 个小时试图弄清楚这一点,并试图重新设计我启动服务的方式,这通常是通过以下方式完成的:

Macintosh-2:~ clement$ python /Users/clement/Desktop/\#Minecraft/index.py

谢谢!

4

1 回答 1

1

我相信我已经找到了答案。

解决:

  1. 将 CD 放入包含 main.py(或在我的情况下为 index.py)的目录中
  2. 确保您的 HTML 文件位于您 cd 进入的名为“模板”的目录中
  3. 运行方式:python [main.py 的完整路径]

希望这可以帮助有类似问题的人:)

(注:运行 OS X 10.8.1)

于 2012-10-22T17:07:19.387 回答