sqlalchemy / flask查询中的类型错误(type error in sqlalchemy/flask query)

编程入门 行业动态 更新时间:2024-10-28 08:19:53
sqlalchemy / flask查询中的类型错误(type error in sqlalchemy/flask query)

我想知道我是否可以通过我使用Flask-sqlalchemy和postgres数据库创建的应用程序的错误获得一些帮助。 我目前有一个年份列表(整数)。 列表的元素取决于用户选择的年份。 通过列表,我在下面搜索我的数据库中的结果,这些结果的财政年度与我的列表中的年份相匹配:

@main.route('/searchresults') def yearresults(): entries = db.session.query(Post).filter(Post.fiscalyear.in_(list)) return render_template('yearsearch.html', entries=entries)

然而,当我运行时,我得到了

TypeError: 'type' object is not iterable

错误发生在查询行(db.session.query(Post).filter ...)

我知道我的代码在我查询一个特定年份时有效,但我试图让它与多个未知数一起工作。 我想知道是否有人看到解决方案或更好的方法来做到这一点。

提前致谢!

I was wondering if I could get some help on an error I have with an app I am making with Flask-sqlalchemy and a postgres database. I currently have a list of years (ints). the elements of the list depend on the year that the user selects. With the list I make a query below searching for results in my database that have fiscal years matching the years in my list:

@main.route('/searchresults') def yearresults(): entries = db.session.query(Post).filter(Post.fiscalyear.in_(list)) return render_template('yearsearch.html', entries=entries)

When I run this, however, I get

TypeError: 'type' object is not iterable

The error occurs on the line of the query (db.session.query(Post).filter...)

I know my code works when I query with one specific year, but I'm trying to get it to work with multiple unknowns. I was wondering if anyone sees a solution or a better way to do this.

Thanks in advance!

最满意答案

代码中的list是Python内置对象list (类型)。

请在那里提供实际的列表对象。

list in your code is a Python built-in object list (type).

Please provide actual list object there.

更多推荐

本文发布于:2023-08-05 20:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   类型   flask   sqlalchemy   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!