国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

python - flask用ajax做后臺登陸交互,驗(yàn)證密碼后,如何重新定位到index.html上?

瀏覽:125日期:2022-07-18 08:55:56

問題描述

flask用ajax做后臺登陸交互,驗(yàn)證密碼后,不會重新定向到index上面去。ajax代碼如下:

$.ajax({url:’/login’,type:’post’,data:{ user:$(’#user’).val(), password:$(’#password’).val(),},beforeSend:function(){ $.messager.progress({text:’正在登陸準(zhǔn)備中......’, });},success:function(data,response,status){ $.messager.progress(’close’); if (data>0){location.href=’/templates/index.html’; }else{$.messager.alert(’登陸失敗!’,’用戶名或密碼錯(cuò)誤!’,’warning’,function(){ $(’#password’).select();}); }} });

在登陸界面填入賬號密碼后,post到了login去處理,login代碼如下:

def login(): user1=request.values.get(’user’) password=request.values.get(’password’) if user1:mydb=mysql.connector.Connect(database=’dh_inf_manage’,user=’root’,password=’password’)mycur=mydb.cursor(dictionary=True)query_emp=’select * from dic_user where emp_sn=%s’mycur.execute(query_emp%user1)emp_result=mycur.fetchone()if emp_result is not None: emp_sn=emp_result[’emp_sn’] emp_name=emp_result[’name’] hashpw=emp_result[’password’] emp_dept=emp_result[’emp_dept_sn’] if check_password_hash(hashpw,password):session[’emp_dept’] = emp_deptuser=User()login_user(user)redirect(url_for(’index’))return ’1’ else:return ’0’else: return ’0’ return render_template(’login.html’)

index代碼:

@app.route(’/’,methods=[’GET’, ’POST’])@login_requireddef index(): return render_template(’index.html’)

問題解答

回答1:

location.href=’/’;

標(biāo)簽: Python 編程
主站蜘蛛池模板: 辉县市| 浦北县| 华容县| 兴义市| 张家界市| 游戏| 谷城县| 军事| 永顺县| 高要市| 武隆县| 绥德县| 电白县| 庆安县| 冕宁县| 光泽县| 友谊县| 镇坪县| 屯昌县| 高要市| 克什克腾旗| 云阳县| 繁昌县| 平南县| 历史| 昆山市| 美姑县| 台南县| 蒙山县| 徐水县| 古蔺县| 翁源县| 方城县| 泗水县| 彩票| 广水市| 洛南县| 西峡县| 宽甸| 邵武市| 全南县|