我需要将arg发送到我的flask函数,但是出现“缺少1个必需的位置参数”错误。我应该怎么做才能解决这个问题。
check = True
@app.route('/sortbysalary', methods=['POST'])
def sortbysalary(check):
if request.method == 'POST':
if check is True:
conn = sqlite3.connect('employees.db')
c = conn.cursor()
with conn:
# no case carre
c.execute("SELECT * FROM employee ORDER BY pay COLLATE NOCASE DESC")
query = c.fetchall()
check = False
print(check)
else:
conn = sqlite3.connect('employees.db')
c = conn.cursor()
with conn:
# no case carre
c.execute("SELECT * FROM employee ORDER BY pay COLLATE NOCASE ASC")
query = c.fetchall()
check = True
print(check)
return render_template('show.html', query=query)
答案 0 :(得分:0)
如果您尝试将“ check”变量从另一条路线传递给此视图函数,则通常的做法是使用路线装饰器。即:
@app.route('/sortbysalary/<check>', methods=['POST'])
def sortbysalary(check):
...
或者,您可以使用Flask的会话来执行更安全的操作。不确定这是否适用于此。