2012-10-22 39 views
0

最近我一直在試圖學習WebPy,當試圖在教程中使用模板(http://webpy.org/docs/0.3/tutorial)時,在嘗試訪問該頁面時遇到此錯誤。WebPy:AttributeError沒有名爲index的模板

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 

我看了這個Question上SOF,但我不能讓它在我的情況下工作。我花了大約4個小時試圖弄清楚這一點,並試圖返工我推出的服務的方式,通常通過做:

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

謝謝!

+0

如果你展示了一些源代碼而不僅僅是回溯,它會有幫助 –

+1

我認爲你確實遵循了'讓我們爲我們的模板創建一個新目錄(我們會稱之爲模板)。在裏面,創建一個名稱以HTML結尾的新文件(我們將其稱爲index.html)。現在,在裏面,你可以編寫普通的HTML:'? –

回答

0

我相信我找到了答案。

要解決的

  1. 光盤放入含有main.py的目錄(或在我的情況index.py)
  2. 確保你的HTML文件在您cd'd進入目錄的目錄所謂的 '模板'
  3. 通過運行:蟒蛇[完整路徑在main.py]

希望這有助於人們類似問題:)

(注意:運行OS X 10.8.1)