Ich verwende Flask-JSGlue, die ein Flask
Objekt mit Methoden wie url_for
in JavaScript bereitstellen soll. Ich bekomme Uncaught ReferenceError: Flask is not defined
in scripts.js
. Warum erhalte ich diesen Fehler?Flask-JSGlue bietet kein Flask-Objekt für JavaScript-Datei
from flask_jsglue import JSGlue
app = Flask(__name__)
JSGlue(app)
@app.route("/city")
def city():
return render_template("city.html")
scripts.js
:
$(document).ready(function() {
if (location.pathname == '/city') {
$.getJSON(Flask.url_for('city'), parameters).done(function (json_city, x, y) {
document.body.style.backgroundImage = json_city['background_filename'];
});
}
});