【问题标题】:Query is not running via flask_mysql查询未通过 flask_mysql 运行
【发布时间】:2019-06-19 03:25:20
【问题描述】:

我无法从选择查询中检索数据,因为虽然存储在变量中的数据没有将值传递给选择查询

from flaskext.mysql import MySQL

@app.route("/loginscr/",methods =['POST'])
def loginscr():

    username = request.form['username']
    password = request.form['password']

    print(request.form.to_dict())
    cursor = connection.cursor()
    cursor.execute('Select * from basics where username = %s AND password = %s',(username,password))
    account = cursor.fetchone()
    if account is not None:
        print("Successfull")
    else:
        print("UnSuccessfull")
    return "true"

【问题讨论】:

    标签: python mysql python-3.x flask mysql-python


    【解决方案1】:

    fetchone() 不返回 int。替换

    if(account == 1):
    

    if account is not None:
    

    或者,更 Pythonic,

    if account:
    

    【讨论】:

      猜你喜欢
      • 2012-01-25
      • 2015-06-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多