Genshi和CherryPy中的特定于上下文的导航

使用带有CherryPy的Genshi模板引擎,我需要一个特定于上下文的站点导航,为登录用户显示不同的菜单。

用户由CherryPy会话识别。

为登录用户显示不同菜单的最佳方式是什么?

采纳答案:

我们检查用户是否已登录...

import cherrypy
from genshi.template import TemplateLoader

@cherrypy.expose
def index(self):
tmpl = loader.load('index.html')

if(cherrypy.session.get('_cp_Email')):
    return tmpl.generate(title='Geddit').render('html', LoggedIn=True)
else:
    return tmpl.generate(title='Geddit').render('html', LoggedIn=False)

你的模板会喜欢这样的......

            if (LoggedIn) {
              # Logged In menu
            } else {
              # not Logged In menu
            }

如果是,我们将变量发送到模板以显示Log Out而不是Login。

我们正在使用它进行身份验证...

http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions

出于安全原因包括注释。 希望这可以帮助!

author: andrew-kloos

参考更多解答: Context specific navigation in Genshi and CherryPy ,转载请保留出处Genshi和CherryPy中的特定于上下文的导航及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:python