I am trying to access a mongodb record within a javascript function to display the document on a webpage. Using the Bottle framework with pymongo, I have tried to first encode the mongodb document as a JSON object to pass to my javascript function.

```
@bottle.route('/view/<_id>', method = 'GET')
def show_invoice(_id):
    client = pymongo.MongoClient("mongodb://localhost")
    db = client.orders
    collection = db.myorders
    from bson.objectid import ObjectId
    result = collection.find_one({'_id': ObjectId(_id)})
    temp = json.dumps(result,default=json_util.default)
    print "temp: " + temp

    return bottle.template('invoice', rows = temp)

```

When I try to display the document within my HTML page with the javascript function, nothing happens. However, when I call the variable, rows, that I am trying to pass as {{rows}} within the body of the HTML it does display. It seems it is only the JS function that does not display anything. 

```
    <!DOCTYPE html>
 <html>
  <head>
    <head>
    <title>Invoice Report</title>
    <script type="text/javascript">
    function fillTable()
    {
      var obj = {{rows}};
      document.write(obj);

    }
    </script>
   </head>
  </head>
  <body onload="fillTable()">
     <div class="invoice">
     </div>
     <h4>Rows from body</h4> {{rows}}

  </body>
 </html>

```

I tried to use jQuery to deserialize the JSON object rows with the function

```
jQuery.parseJSON(rows);

```

and even as
 jQuery.parseJSON({{rows}});

I also tried to make the variable unescaped everywhere possible as {{!rows}}
So does anybody see what I am doing wrong? How do I take a mongodb document with pymongo, and use bottle to display it on a webpage? I realize that similar questions have been asked, but I can't seem to get anything I have found to work in my particular situation.