亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

燒瓶登錄重定向生成 302 但瀏覽器不會像其他功能一樣更新

燒瓶登錄重定向生成 302 但瀏覽器不會像其他功能一樣更新

慕雪6442864 2022-10-27 16:12:17
我正在為我的 webapp 實現登錄功能。由于某種原因,客戶端/瀏覽器在通過我的登錄功能發送時沒有實現重定向。但是,當我使用注銷功能重定向時,它工作得很好。我實際上只是從這里復制了代碼https://realpython.com/using-flask-login-for-user-management-with-flask/自周一以來我一直在閱讀一些帖子,他們都指出必須做 window.location.replace() 但是我不是 JS 或 JQUERY 的家人,所以我不確定如何實現與我的登錄功能同步。@app.route("/login/", methods=["GET", "POST"])def login():    print("current user is:{}".format(current_user))    data_dict = config.DATA    form = CredentialForm()    if form.validate_on_submit():        db.session.commit()        user = db.session.query(User).filter_by(email=form.email.data).first()        if user:            if user.password == form.password.data:                user.authenticated = True                db.session.add(user)                db.session.commit()                login_user(user, remember=True)                print("current user is:{}".format(current_user))                return redirect(request.args.get("next") or url_for('dashboard'))    return  render_template('login.html',intial_data=data_dict,form=form)
查看完整描述

1 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

如果您在 ajax 中發送請求,當您收到響應時,如果response.redirected為true,您可以使用window.location.reload()重新加載網頁。例如使用fetch進行 ajax 請求


fetch("/login", {

      method:"POST",

      headers: new Headers(),

      body: ...

}).then( (response) => {

       /*

         if redirect is true new url is ready underthehood, reload the page will trigger new route.

       */

       if(response.redirected) window.location.reload();

       ...

}).catch( (error) => console.error("[-] Error with the request"));

獲取 api 文檔


查看完整回答
反對 回復 2022-10-27
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號