Python 将html打印到控制台而不是重定向
我在授权蓝图中有以下代码:Python 将html打印到控制台而不是重定向,python,flask,Python,Flask,我在授权蓝图中有以下代码: @auth.route('/login/',methods=['POST','GET']) def login(): email = request.form.get('email',type=str) password = request.form.get('password',type=str) error = None if email != None and password !=
@auth.route('/login/',methods=['POST','GET'])
def login():
email = request.form.get('email',type=str)
password = request.form.get('password',type=str)
error = None
if email != None and password != None:
if verify_user(email,password):
user = next((item for item in app.config['AUTHORIZED'] if item["email"] == email), None)
session['name'] = user['name']
flash("welcome " + session['name'] + '!')
return redirect(url_for('admin.show'))
error = "invalid credentials"
return render_template('auth/index.html',error=error)
下面是我在登录时重定向到的管理蓝图:
@admin.route('/admin/',methods=['GET'])
def show():
if not 'name' in session:
return abort(403)
return render_template('admin/index.html')
然而,当我成功登录时,flask仅将html从
admin/index.html
打印到Chrome和Firefox中的javascript控制台。既然您提到了JS控制台,那么您大概是通过Ajax发出此请求的。因此,您的Ajax处理程序需要执行任何重定向。当您从html请求表单数据时,请确保您的按钮具有type=“submit”
而不是type=“button”
。更改此选项为我解决了问题
<form class="form-logIn" action="/logIn" method="post">
<label for="email" class="sr-only">Email address</label>
<input type="email" name="email" id="email" class="form-control" placeholder="Email address" required autofocus>
<label for="password" class="sr-only">Password</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
<button id="btnLogIn" class="btn btn-lg btn-secondary btn-block" type="submit">Log In</button>
</form>
电子邮件地址
密码
登录
你能举个例子吗?:)