I'm trying to send an array from a Python function to JavaScript using Flask, but the problem is I keep getting Unexpected token { in my code and Uncaught SyntaxError: Unexpected token { in my console.
This is my Python code, hashtags.py:
import tweepy
import json
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/map/')
@app.route('/map/<trends>')
import tweepy
import json
from flask import Flask, request, render_template
def trend_hash(id):
for location in api.trends_place(id):
for trend in location["trends"] :
trends = trend["name"]
with app.app_context():
return render_template("/map.html", trends=json.dumps(trends))
trend_hash(1939753)
And this is my script in map.html (Where the problem occurs):
function getHashtags() {
var trends = ;
console.log(trends);
console.log("done"); }
And if I change this line:
var trends = ;
to:
var trends = (trends|safe);
I get this error in my console:
Uncaught ReferenceError: safe is not defined
I also tried this statement:
var trends = JSON.stringify();
But unfortunately I still get the same problem.
My framework: Cloud9
I've searched but no solution seems to work.
Thank you.
Aucun commentaire:
Enregistrer un commentaire