WebPy:AttributeError没有名为index的模板

时间:2012-10-22 16:49:46

标签: python html indexing web.py

最近我一直在尝试学习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上看过这个Question,但是在我的情况下我无法让它工作。我花了大约4个小时试图解决这个问题并尝试重新启动我启动服务的方式,这通常是通过以下方式完成的:

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

谢谢!

1 个答案:

答案 0 :(得分:0)

我相信我找到了答案。

要解决:

  1. 将CD放入包含main.py(或在我的情况下为index.py)
  2. 的目录中
  3. 确保您的HTML文件位于您所在的目录中名为“templates”
  4. 的目录中
  5. 通过:python [main.py的完整路径]
  6. 运行

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

    (注意:运行OS X 10.8.1)