Py学习  »  问与答

使用django_chartit报错字符串不能解码/编码,求帮助!

673890989 • 9 年前 • 2861 次点击  

数据库采用mysql,数据库编码格式已改为utf-8:

views.py:

keyworkdata = \
    PivotDataPool(
        series =
        [{'options': {
            'source': LOrder.objects.all(),
            'categories': 'com_chnl_name'},
          'terms': {
            'num': Count('serv_id')}}
        ])
keyworkchart = PivotChart(
    datasource = keyworkdata,
    series_options =
      [{'options':{
          'type': 'line',
          'stacking': True},
        'terms': ['num']}])
return render(request, 'keywork/index.html',
              {'keyworkchart':keyworkchart,
               })

模板中:

{% load chartit %}
{{ keyworkchart|load_charts:"container" }}
<div id='container'> Chart will be rendered here </div>

以上都是参考官方写的,这里运行网页就报'ascii' codec can't encode characters in position 0-8: ordinal not in range(128)错误

模型里面是用的def unicode(self):,因为这里python是2.7版本,不知道咋回事了,唉! 谁用过django_chartit帮忙说下哪里出问题的了,网上资料太少了

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1418
文章 [ 1 ]  |  最新文章 9 年前
673890989
Reply   •   1 楼
673890989    9 年前

刚在github上搜了一下django_chartit,上面有说道这个问题,说This specifically seems related to "lv = tuple(map(str, lv))", when "lv" contains an en-dash. I suspect I'll get even more of these errors on my data since I can't reasonably force all of my data into ASCII. 差不多是说当lv中包含短破折号时,所有数据不能合理的转换成ASCII,明天有时间试试,看是不是这个问题。