呈现时捕获到TypeError:\uu init\uuu()得到意外的关键字参数“use\u decimal”

2024-04-26 17:20:14 发布

您现在位置:Python中文网/ 问答频道 /正文

运行程序时,我收到以下错误消息

Caught TypeError while rendering: __init__() got an unexpected keyword
argument 'use_decimal'

这是我的密码 我正在使用jquery 1.6.4

def load_charts(chart_list=None, render_to=''):
    embed_script = (
      '<script type="text/javascript">\n'
      'var _chartit_hco_array = %s;\n</script>\n'
      '<script src="%s" type="text/javascript">\n</script>')

    if chart_list is not None:
        if isinstance(chart_list, (Chart, PivotChart)):
            chart_list = [chart_list]
        chart_list = [c.hcoptions for c in chart_list]
        render_to_list = [s.strip() for s in render_to.split(',')]
        for hco, render_to in izip_longest(chart_list, render_to_list):
            if render_to:
                hco['chart']['renderTo'] = render_to
        embed_script = (embed_script % (simplejson.dumps(chart_list, 
                                                         use_decimal=True),
                                        CHART_LOADER_URL))
    else:
        embed_script = embed_script %((), CHART_LOADER_URL)
    return mark_safe(embed_script)

Tags: totextinnoneforifusetype
2条回答

为了拯救另一个灵魂,痛苦的时间花了。

    pip install simplejson

注意:这应该在您的project virtual env中完成。

simplejson.dumps的签名是(请参见documentation):

dumps(obj, skipkeys=False, ensure_ascii=True, 
      check_circular=True, allow_nan=True, cls=None)

如您所见,没有use_decimal参数。。。但你这样称呼它:

simplejson.dumps(chart_list, use_decimal=True)

编辑:事实上,更多的挖掘带来了this other documentation。似乎use_decimal参数是在simplejson库的某个版本中添加的。。。我建议您将库版本升级到最新版本!

相关问题 更多 >