我想知道我是否可以通过我使用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 iterableThe 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.
更多推荐
发布评论