【发布时间】:2014-08-05 05:35:30
【问题描述】:
我正在尝试在我的 Flask 应用程序中运行 SQLAlchemy 查询。我想获取 URL 参数('menu')并将它的值替换到我的查询中......
@app.route('/attend/')
def attend_by_role():
role = request.args.get("menu")
attendee_by_role = session.query(Attendee).filter_by(role = True)
return render_template("attending.html", attendee = attendee_by_role)
这是直接在我的表中寻找role,这是我不想要的。我想查找由 URL 参数定义的 role 变量是什么。
【问题讨论】:
-
例如,如果
role == 'admin'你只想要'admin'作为角色的条目? -
我的表有几列(即前端、后端、设计、管理员),所有列都有布尔条目值。我想运行一个查询,以便
role表示列名并仅返回条目值为 True 的行(在该列中)。这可能很简单,但我是 SQL Alchemy 的新手! -
您的意思是要按
menu参数指定的列进行过滤吗?试试.filter_by(**{role: True})。
标签: python postgresql flask sqlalchemy flask-sqlalchemy