2017-05-19 12 views
0

Flask Blueprintを使用して別のファイルからルートを作成しようとしています。これは私の「catalog.pyファイル:Python Flask:render_template - 'dict'オブジェクトが呼び出し可能でない

from flask import Blueprint, make_response, render_template 
from models.catalog import Catalog 

catalog_url = Blueprint('catalog_url', __name__) 

@catalog_url.route("/") 
@catalog_url.route("/catalog") 
def show_all_catalogs(): 
    try: 
     catalogs = Catalog.find_all_catalogs() 
     return render_template('publiccatalogs.html', catalogs=catalogs) 
    except: 
     return {'message': 'Internal Server Error'}, 500 

これが私です "であるapp.py" ファイル:

from catalog import catalog_url 
app = Flask(__name__) 
app.register_blueprint(catalog_url) 

しかし、私が入力したときには "localhost:5000 /カタログ"、それはこのエラーを返します。

TypeError: 'dict' object is not callable 

私は、彼らがうまく働いていた、プレーンテキスト、さらにはJSONを返すみました。しかし、私は「render_template」を使用しようとすると、私は同じエラーを取得しておく。

+0

エラーが発生するのはどの回線ですか? – moritzg

+0

"render_template( 'publiccatalogs.html'、カタログ=カタログ)を返します。私はそれを "返す" Hello World 'に置き換えます! " "return jsonify(... catalogs ...)"それはちょっとうまくいった@moritzg –

+1

私はそれがむしろ 'return {'message': 'Internal Server Error'}、500'で起こったと思います。あなたはJSONを返そうとしていますか? ?それはそれを行う方法ではないからです。 – polku

答えて

0

try exceptがあり、コードreturn render_template('publiccatalogs.html', catalogs=catalogs)が正しい。しかし、私はhtmlテンプレートが見つからないと思うし、この例外が起きると、return {'message': 'Internal Server Error'}, 500の部分書式が間違っています。

  • ストリング
  • Responseオブジェクト(またはサブクラス)
  • のタプル(文字列、ステータス、ヘッダ)または(列:フラスコに

    、ビューは、次のいずれかを返す必要があります、ステータス)

  • 有効なWSGIアプリケーション
+0

ええ、私は今それを理解しました!ありがとう –

関連する問題