I'm trying to run a SQLAlchemy query in my Flask app using. I want to grab the URL parameter ('menu') and substitute it's value into my query...
@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)
This is directly looking for role in my table, which I don't want. I want to look up what the role variable is as defined by the URL parameter.
role == 'admin'you want only the entries that have'admin'as a role?rolerepresents the column name and returns only the rows where the entry values are True (in that column). This is probably simple but I'm new to SQL Alchemy!menuparameter? Try.filter_by(**{role: True}).