【问题标题】:flash messaging not appearing in flask烧瓶中没有出现闪存消息
【发布时间】:2018-11-27 11:06:42
【问题描述】:

当我登录时没有显示flash消息。我该如何解决它?

我的登录定义如下

@app.route("/login",methods=["GET","POST"])
def login():
  form=LoginForm(request.form)
      if request.method=="POST":
        username=form.username.data
        password_entered=form.password.data

cursor=mysql.connection.cursor()
sorgu="Select * From users where username = %s"
result=cursor.execute(sorgu,(username,))
if result>0:
  data=cursor.fetchone() 
  real_password=data["password"]
  if sha256_crypt.verify(password_entered,real_password):
      flash("Başarıyla giriş yaptınız...","info")
      session["logged_in"]=True
      session["username"]=username
      return redirect(url_for("index"))
  else:
      flash(("wrong password","warning"))
      return redirect(url_for("login"))

else:
  flash("this username is not avaible","warning")
  return render_template("login.html",form=form)

我不知道为什么它不工作。登录时重定向 url 功能工作但没有出现 flash 消息。

【问题讨论】:

    标签: python flash flask


    【解决方案1】:

    你传入一个参数(一个元组)而不是两个。

    flash(("wrong password","warning")) 更改为flash("wrong password","warning")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      相关资源
      最近更新 更多