显然,您没有将任务对象传递给模板,这就是为什么您不能使用它。我没用过烧瓶,但你可以把task和{}当作口述来传递return render_template("task_details.html", {'links': links, 'task': task))
这是一个使用battlepy和ajax的例子,非常类似于flask
ajax调用:
^{pr2}$
Python:@route('/methods/', method='GET')
def getUserStatus(id='0'):
# Get user status info
try:
con = pymysql.connect(user=dbUser, passwd=password, host=dbHost, port = dbPort, db=database)
cursor = con.cursor()
status = cursor.execute("SELECT account_number,account_type FROM payment_methods")
status = cursor.fetchall()
con.close()
# handle mysql errors
except pymysql.Error as error2:
message = ({"result":"error","error_name":error2[1]})
return json.dumps(message)
# Preparing response
q = len(status)
columns = zip(*status)
acc_n =columns[0]
acc_t = columns[1]
#acc_n = [x for (x,y) in status]
#acc_t = [y for (x,y) in status]
message = ({"result":"OK","q":q,"acc":acc_n,"name":acc_t})
# Return
return json.dumps(message)