1

我有一个多页面的应用程序,在 python 2.7 上运行。该应用程序在本地工作得很好,但是一旦我部署它,在我登录我创建的登录页面后,主页(斜杠后没有任何内容)完全空白。我可以在应用程序的其他页面中输入地址,它们就可以正常显示(如果我已登录)

URL 是 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')

任何帮助,将不胜感激!谢谢

4

0 回答 0