【发布时间】:2011-07-25 02:58:42
【问题描述】:
我是 Python 和 Web.py 的新手,但我对这个问题感到很头疼。我有一个代码布局,其中我的app.py 文件位于我网站的根目录中。所有页面都在一个子目录中,名为pages。这是我的 app.py 代码
import web
import page.index
urls = (
'/', 'page.index.index',
)
render = web.template.render('templates/', base = "layout") # Start the template
app = web.application(urls, globals()) # Start the app
if __name__ == "__main__":
app.run()
现在,它完美地执行了。现在,在 index.py 文件中,这是我的代码:
class index:
def GET(self):
testing = 'Hello World'
return render.index(testing)
我得到的错误是这样的:
<type 'exceptions.NameError'> at /
global name 'render' is not defined
Python /Volumes/Local Disk 2/Work/Casting Board/com/index.py in GET, line 3
Web GET http://127.0.0.1:8080/
基本上,我正在尝试从名为 page.index 的 moucle 访问函数(或者它是方法或类。只是来自 PHP,所以不知道终端)render。我该如何解决这个问题?
【问题讨论】:
-
您确定不需要只使用
import pages。哪个会查找 pages 文件夹?请参阅github.com/alexksikes/mailer/blob/master/application.py,了解您正在尝试做的示例。