我有一个包含多个页面的应用程序,在python 2.7上运行。 该应用程序在本地工作得很好,但是一旦我部署它,在我登录我创建的登录页面后,主页面(斜杠后面没有任何内容)完全空白。我可以在应用程序中的其他页面输入地址,它们会很好(如果我已登录)
网址为hoosierhillsfoodbank.blogspot.com 现在唯一的用户是admin,admin。
涉及大量代码,所以我只发布我认为可能相关的内容。这是HTML页面的顶部:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Volunteer Kiosk | Home</title>
<link href="../static/style.css" rel="stylesheet" type="text/css" />
</head>
以下是登录后加载主页的代码
class LoginPage(BaseHandler):
def get(self):
if self.session.get('user'):
self.redirect('/') #already logged in, go to homepage
else:
doRender(self, 'login.html')
def post(self):
in_username = self.request.get('username')
in_password = self.request.get('password')
self.session['user'] = '' #logout user if still logged in
if in_password == '' or in_username == '':
doRender(self, 'login.html',
{'error': 'Please specify Username and Password'})
return
result = User.all().filter('username =', in_username).get()
if result and security.check_password_hash(in_password, result.password) :
logging.info('session[user] ='+ self.session['user'])
self.session['user'] = in_username
self.session['usertype'] = result.usertype
self.session['msg'] = 'Welcome '+self.session['user']
self.redirect('/')
else:
doRender(self, 'login.html',
{'error': 'Incorrect Username or Password'})
使“/”转到主页的更多代码
def doRender(handler, tname='home.html', values={}):
temp = os.path.join(os.path.dirname(__file__),
'templates/' + tname)
if not os.path.isfile(temp):
return False
#make a copy of values and add the path
newval = dict(values)
newval['path'] = handler.request.path
#check if user logged in
val = handler.session.get('user')
newval['user'] = val
#if logged in, add userlinks
if handler.session.get('user') and handler.session.get('usertype') < 2:
newval['userlinks'] = [('/','Home'),
('/Programs','Programs'),
('/Volunteers','All Volunteers'),
('/Individuals','Individuals'),
('/ServiceLearners','Service Learners'),
('/Groups','Groups'),]
if handler.session.get('usertype') == 0:
newval['userlinks'].append(('/users', 'Users'))
#check if there's a msg, add it, then delete it
newval['msg'] = handler.session.get('msg')
handler.session['msg'] = ''
handler.response.write(template.render(temp, newval))
return True
当然还有处理程序
class MainPage(BaseHandler):
def get(self):
#check if logged in, otherwise redirect
if self.session.get('user'):
doRender(self, 'home.html')
else:
self.redirect('/login')
class Home(BaseHandler):
def get(self):
if self.session.get('user'):
time.sleep(.5)
doRender(self, 'home.html')
任何帮助将不胜感激!谢谢