我使用Flask-JSGlue,它應該在JavaScript中爲Flask
對象提供類似url_for
的方法。我在scripts.js
得到Uncaught ReferenceError: Flask is not defined
。爲什麼我得到這個錯誤?Flask-JSGlue不向JavaScript文件提供Flask對象
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'];
});
}
});