python - 从其他方法返回方法的问题
问题描述
我有两种方法需要从另一种方法返回。问题是返回其他方法的方法正在返回首先出现的方法。
@app.route('/dashboard')
@is_logged_in
def dashboard():
return pending_registration()
return registered_customers()
return render_template('dashboard.html')
这是返回其他方法的方法。这里就像pending_registration()
一开始一样,所以它正在返回它也正在返回accept
andreject
方法而不是registered_customers()
.
@app.route('/pending')
@is_logged_in
def pending_registration():
cur = mysql.connection.cursor()
result = cur.execute('SELECT * from registration')
data = cur.fetchall()
if result>0:
return render_template('dashboard.html', users=data)
else:
msg = 'No Pending registration'
return render_template('dashboard.html',msg=msg)
cur.close()
# Registered Customers
@app.route('/registered')
@is_logged_in
def registered_customers():
cur = mysql.connection.cursor()
result = cur.execute('SELECT * from company_customers')
data = cur.fetchall()
if result>0:
return render_template('dashboard.html', customers=data)
else:
msg = 'No customers'
return render_template('dashboard.html',msg=msg)
cur.close()
这些是需要返回的 2 个方法
解决方案
如果您希望从 中返回所有函数def dashboard()
,请使用:
def dashboard():
return pending_registration(), registered_customers(), render_template('dashboard.html')
你会得到一个包含三个函数返回值的元组。