为什么我的奇怪结果呈现了用户对象? [英] Why my strange results rendering the user object?

查看:81
本文介绍了为什么我的奇怪结果呈现了用户对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的变量{{current_user.name}}不显示任何内容,并且变量{{username}}而不是Niklas R显示,而是在我用django渲染的页面上显示`(u'Niklas R',).这是基本处理程序中的方法,希望您能告诉我这是怎么回事:

For some reason, my variable {{current_user.name}} doesn't display anything and the variable {{username}} displays instead of Niklas R it displays `(u'Niklas R',) on the page that I render with django. Here is the method from the basehandler that I hope you can tell me what's wrong with:

def render(self, name, **data):
    """Render a template"""
    if not data:
        data = {}
    data[u'js_conf'] = json.dumps({
        u'appId': facebookconf.FACEBOOK_APP_ID,
        u'canvasName': facebookconf.FACEBOOK_CANVAS_NAME,
        u'userIdOnServer': self.user.user_id if self.user else None,
    })
    data[u'logged_in_user'] = self.user
    data[u'message'] = self.get_message()
    data[u'csrf_token'] = self.csrf_token
    data[u'canvas_name'] = facebookconf.FACEBOOK_CANVAS_NAME
    logging.debug('user object: '+str(self.current_user))
    data[u'current_user']=self.current_user,
    data[u'username']=self.current_user.name,
    data[u'facebook_app_id']=FACEBOOK_APP_ID
    self.response.out.write(template.render(
        os.path.join(
            os.path.dirname(__file__), 'templates', name + '.html'),
        data))

推荐答案

这一直在我身上发生,您有一个多余的值,并且变量变成元组.

This happens to me all the time, you have an extra , and the variable becomes a tuple.

将行更改为:

data[u'current_user']=self.current_user
data[u'username']=self.current_user.name

这篇关于为什么我的奇怪结果呈现了用户对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆