我正在尝试使用FlaskBlueprint从另一个文件创建路由。这是我的“目录.py文件:
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
这是我的“应用程序“”文件:
^{pr2}$但当我进去的时候”本地主机:5000/目录,则返回以下错误:
TypeError: 'dict' object is not callable
我试着返回纯文本甚至JSON,它们工作得很好。但是当我尝试使用“render_template”时,我总是得到相同的错误。在
有
try except
,你的代码return render_template('publiccatalogs.html', catalogs=catalogs)
是正确的。但是,我怀疑找不到html模板,然后发生了这个异常,它转到exceptreturn {'message': 'Internal Server Error'}, 500
这个部分格式不正确。在在烧瓶中,视图必须返回以下内容之一:
相关问题 更多 >
编程相关推荐