2016-11-22 32 views
0

私はFlask-JSGlueを使用しています。これはFlaskオブジェクトをJavaScriptでurl_forのように提供することになっています。 Uncaught ReferenceError: Flask is not definedscripts.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']; 
     }); 
    } 
}); 

答えて

0

As the docs explain、あなたのレンダリングされたページのフラスコJSGlueのスクリプトを含める必要があります。 の前にの内容を含める必要があります。

<head> 
    {{ JSGlue.include() }} 
    <script src="{{ url_for('static', filename='script.js') }}"></script> 
</head> 
-1

あなたが最初のフラスコをインポートする必要があります。

from flask import Flask