0

I'm trying to display a chart with help of Highchart by following this solution:

Passing Django Database Queryset to Highcharts via JSON

But I keep getting this error:

'SafeText' object has no attribute 'get'

Which I have been trying to find for days.

Still new to this and appreciate your help, folks!

EDIT

Django: 1.10
Python: 3.6


views.py

class ChartData(object):
    def check_valve_data(self):
        data = {'member_no': []}

        people = Member.objects.all()

        for unit in people:
             data['member_no'].append(unit.member_no)

        return data


 def chartViewHigh(self, chartID='chart_ID', chart_type='column', chart_height=500):
     data = ChartData.check_valve_data(self)

     chart = {"renderTo": chartID, "type": chart_type, "height": chart_height, }
     title = {"text": 'Check Valve Data'}
     xAxis = {"title": {"text": 'Member'}, "categories": data['member_no']}
     yAxis = {"title": {"text": 'Data'}}

     return render_template('chart/chartViewHigh.html', {'chartID': chartID, 'chart': chart,
                                                    'title': title, 'xAxis': xAxis, 'yAxis': yAxis})

chartViewHigh.html

{% extends 'base.html' %}

{% load staticfiles i18n %}

{% block head %}
  <link href="{% static 'css/chart.css' %}" rel="stylesheet">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="https://code.highcharts.com/highcharts.js"></script>
      <script src="https://code.highcharts.com/modules/exporting.js"></script>

 {% endblock head %}

 {% block main %}

<h1 align="center">Analysis</h1>

{% block content %}
   <div id={{ chartID }} class="chart" style="height:100px; width:100%"></div>
{% endblock %}


{% block extrajs %}
<script>
   var chart_id = {{ chartID }};
   var chart = {{ chart }};
   var title = {{ title }};
   var xAxis = {{ xAxis }};
   var yAxis = {{ yAxis }};
</script>


<script>
$(document).ready(function() {
   $(chart_id).highcharts({
       chart: chart,
       title: title,
       xAxis: xAxis,
       yAxis: yAxis,
   });
});
</script>
{% endblock %}

{% endblock main %}

urls.py

urlpatterns = patterns[
    url(r'^chartViewHigh/$', views.chartViewHigh, name='chartViewHigh'),
]
Community
  • 1
  • 1
Niknak
  • 583
  • 1
  • 8
  • 22

1 Answers1

2

It looks like chartViewHigh is not a valid Django view. Every Django view takes an HttpRequest object as its first parameter, typically called request - but chartViewHigh does not.

See this page of the docs for the essentials of a Django view: https://docs.djangoproject.com/en/1.11/topics/http/views/

And see the answer to this question, which is the same problem: Django + trac-wiki to html markdown 'SafeText' object has no attribute 'get' - the error message arises because the function is not taking a request and returning a response object.

Also I don't think render_template is a Django shortcut - is it Flask?

Community
  • 1
  • 1
birophilo
  • 912
  • 10
  • 20
  • Yes, it is Django 1.10 and I forgot to add the details, so sorry. Thank you so much! Now I have another problem that data is not appearing in the chart: http://stackoverflow.com/questions/43988877/django-cant-get-highchart-to-display-data Please take a look, if you can. – Niknak May 16 '17 at 06:42