Google visualization api on app engine not working

2019-09-20 00:21发布

问题:

I'm trying to render the sortable table that's provided in Google visualization API in my app on app engine, but it's not working. The app is written in python and uses the django framework.

When I copy the generated HTML/Javascript and save it as a plain html file locally, it works just fine. This leads me to believe that the problem is that http://www.google.com/jsapi'> is not getting included or is not able to run.

Anyone else run into this? Am I missing some configuration piece in app.yaml?

Thanks!

EDIT: Here's the HTML that is being produced:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 <head>
   <title> 
      Test
   </title> 
   <link href="/css/css.css" rel="stylesheet" type="text/css" /> 
    <script type='text/javascript' src='http://www.google.com/jsapi'></script> 
    <script type='text/javascript'> 
      google.load('visualization', '1', {packages:['table']});
      google.setOnLoadCallback(drawTable);
      function drawTable() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Number');
        data.addColumn('string', 'Status');
    data.addColumn('string', 'Nickname');
        data.addColumn('string', 'Target');
    data.addColumn('string', 'Recording');
        data.addRows(2);

        data.setCell(0, 0, '0987654321');

    data.setCell(0, 1, 'Active');

        data.setCell(0, 2, 'Nothing');
        data.setCell(0, 3, '1234567890');

    data.setCell(0, 4, 'Enabled');

    data.setCell(1, 0, '0987654321');

    data.setCell(1, 1, 'Active');

        data.setCell(1, 2, 'Nothing');
        data.setCell(1, 3, '1234567890');

    data.setCell(1, 4, 'Enabled');


       var table = new google.visualization.Table(document.getElementById('table_div'));
       table.draw(data, {showRowNumber: true});
      }
    </script> 
 </head> 
 <body> 
    <div id='table_div'></div> 
 </body> 
</html> 

This works fine if saved as an html file.

app.yaml:

application: testapp
version: 2
runtime: python
api_version: 1

handlers:
- url: /(.*\.(mp3|wav))
  static_files: \1
  upload: (.*\.(mp3|wav))

- url: /css
  static_dir: css

- url: /.*
  script: main.py

回答1:

Wait, where are you doing the rendering? The visapi stuff goes in the client-side. Is that where you have it? (Sorry if that's obvious; it's really not entirely clear from the way you wrote the question.)

More details would definitely help.



回答2:

In case anyone else has this issue - I messed up headers of the page generated by rendering with the same function I created for XML output.

Including this killed it: handler.response.headers["Content-Type"] = "text/xml"