没有名为index error的模板

时间:2012-11-20 00:48:13

标签: python web.py pythonanywhere

我是Python新手,我正在尝试使用Python Anywhere运行web.py应用程序,但我一直收到No template named index错误。我已修改wsgi.py以使用以下内容:

import web
import MySQLdb

urls = (
  '/', 'index'
)

render = web.template.render('/home/user/templates/')

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:5)

您使用了文字路径'/home/user/templates/'。除非您的用户名实际上是user,否则没有这样的目录,因此尝试从该目录中读取index模板将会失败。

如果您的用户名是rhpt,则将其更改为'/home/rhpt/templates/'

更好的是,您可能希望使用os.path.expanduser('~/templates/')而不是硬编码您的用户名。 (然后您可以将您的代码提供给朋友或客户,他们可以托管它而无需编辑代码。)

相关问题