我是Python和Web.py的新手,但我在這個問題上撕裂了我的頭髮。我有一個代碼佈局,在我的網站的根目錄中有我的app.py
文件。所有頁面都在一個副導演中,名爲pages
。這裏是我的app.py代碼Web.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/
基本上,我試圖訪問功能(或者是方法或類。只是來自PHP,所以不知道從名爲page.index的moucle的末端)render
。我怎樣才能解決這個問題?
你確定你不需要使用'import pages'。哪個會尋找頁面文件夾?請參閱https://github.com/alexksikes/mailer/blob/master/application.py,瞭解您嘗試執行的操作。 – KyleWpppd