私はFlask-JSGlueを使用しています。これはFlask
オブジェクトをJavaScriptでurl_for
のように提供することになっています。 Uncaught ReferenceError: Flask is not defined
はscripts.js
になります。なぜこのエラーが発生するのですか?Flask-JSGlueはFlaskオブジェクトをJavaScriptファイルに提供しません
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'];
});
}
});