我正在嘗試創建一種web服務器withy python和cherrypy。Python網頁登錄錯誤
我希望把htmls放到單獨的文件中,並將它們嵌入到我的python腳本中。我曾經這樣做的代碼是。
@cherrypy.expose
def welcome(self, loginAttempt = None):
""" Prompt the user with a login form. The form will be submitted to /signin
as a POST request, with arguments "username", "password" and "signin"
Dispaly a login error above the form if there has been one attempted login already.
"""
#Debugging Process Check
print "welcome method called with loggedIn = %s" % (loginAttempt)
if loginAttempt == '1':
""" If the user has attempted to login once, return the original login page
with a error message"""
page = get_file("loginPageE.html")
return page
else:
page = """
<form action='/signin' method='post'>
Username: <input type='text' name='username' /> <br />
Password: <input type='password' name='password' />
<input type='submit' name='signin' value='Sign In'/>
</form>
"""
return page
其中loginPageE.html是
<html>
<head>
<title>Failed Login Page</title>
</head>
<body>
<!-- header-wrap -->
<div id="header-wrap">
<header>
<hgroup>
<h1><a href="loginPageE.html">Acebook</a></h1>
<h3>Not Just Another Social Networking Site</h3>
</hgroup>
<ul>
<form action='/signin' method='post'>
Username: <input type='text' name='username' />
Password: <input type='password' name='password' />
<input type='submit' name='signin' value='Sign In'/>
</form>
</ul>
</header>
</div>
</body>
</html>
但是我不斷獲取讀取
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/cherrypy/_cprequest.py", line 606, in respond
cherrypy.response.body = self.handler()
File "/usr/lib/pymodules/python2.7/cherrypy/_cpdispatch.py", line 25, in __call__
return self.callable(*self.args, **self.kwargs)
File "proj1base.py", line 74, in welcome
page = get_file("loginPageE.html")
NameError: global name 'get_file' is not defined
我想知道如果任何人都可以請幫助錯誤消息?
在此先感謝
爲什麼不使用[jinja2](http://jinja.pocoo.org/)等模板引擎? – ThiefMaster 2012-03-18 10:20:43