1

I get this error when I run my webapp. It says that the error is found here:

var rows = ({'CurrentLocation': 'Norwich'}, {'CurrentLocation': 'Sheringham'}, {'CurrentLocation': 'Cambridge'})

This is my code:

def search():
    cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
    cursor.execute("SELECT CurrentLocation FROM driver WHERE OnJourney=0")
    rows = cursor.fetchall()  # data from database
    return render_template("Search.html", rows=rows)
var rows = {{ rows }}
       var row;
       var locations = [];
       for (row in rows) {
        locations.push(row['CurrentLocation']);
       }
       var location;
       for (location in locations) {
        var origin = location;
       }

Is there any way I can pass that dict from python to javascript without getting this error? Thanks for your help

1 Answers1

0

It looks like you're using Django templates.

If so, this answer might help.

Basically, I think you want to turn off autoescaping, so:

{% autoescape off %}
var rows = {{ rows }}
{% endautoescape %}
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90