Python Flask:呈现模板“dict”对象不是callab

2024-06-01 10:29:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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”时,我总是得到相同的错误。在


Tags: 文件fromimport目录urlreturn错误template
1条回答
网友
1楼 · 发布于 2024-06-01 10:29:37

try except,你的代码return render_template('publiccatalogs.html', catalogs=catalogs)是正确的。但是,我怀疑找不到html模板,然后发生了这个异常,它转到exceptreturn {'message': 'Internal Server Error'}, 500这个部分格式不正确。在

在烧瓶中,视图必须返回以下内容之一:

  • 一根绳子
  • 响应对象(或子类)
  • (string,status,headers)或(string,status)的元组
  • 有效的WSGI应用程序

相关问题 更多 >