4Manuals

  • PDF Cloud HOME

如何在Flask中重定向? Download

    如何将文本边界框与pyplot.Rectangle对齐? 导入类问题 在Python数据框中选择列时出错 使用Rabbit的pika确认消息 如何在按住键的同时暂停VideoStream? Python OpenCV TypeError:无法处理此数据类型 使用buildozer不会下载sdl2_image SMTPSenderRefused,421,超出超时 Tensorflow多线程推理比单线程推理慢 关于python中变量的困惑。 python如何使用变量?

下午好! 我正在尝试重定向我的烧瓶应用程序,但是redirect()不起作用,我是Flask中的新手。当用户输入用户名并通过时,代码将验证数据库中的数据,然后,我需要重定向到主页。

这是我的代码的一部分:

@app.route('/Logging',methods=['POST'])
def Logging():
    _email = request.form['inputemail']
    _password = request.form['inputpassword']
    sql = "SELECT * FROM tbl_user WHERE (user_username, user_password) = (%s,%s)"
    val = (_email,_password)
    cursor.execute(sql, val)
    res = cursor.fetchall()
    if np.size(res) > 0:
        return redirect('/Home')
    else:
        return render_template('errorLog.html',error = 'wrong user or pass')

这是“家”的路线:

@app.route('/Home')
def Home():
    return render_template('home.html')

代码可以正常工作,它可以验证输入数据,但不能重定向!我尝试使用url_for,但没有。显然,home.html在正确的文件夹中。此外,命令行打印下一个:

 [30/Dec/2019] "POST /Logging HTTP/1.1" 302 -
 [30/Dec/2019] "GET /Home HTTP/1.1" 200 -

看起来该页面重定向了,但是没有。 请一些帮助和评论?谢谢

编辑:我使用ajax从表单获取数据:

    $(function(){
    $('#btnLogging').click(function(){
    $.ajax({
        url: '/Logging',
        data: $('form').serialize(),
        type: 'POST',

        success: function(response){
            console.log(response);
        },
        error: function(error){
            console.log(error);
        }
        });
        });
        });

这是日志页面的html形式:

    <form name = "form1" class="form-signin">
       <label for="inputemail" class="sr-only">Correo Electrónico</label>
       <input type="email" name="inputemail" id="inputemail" class="form-control" placeholder="Email" required autofocus/>

       <label for="inputpassword" class="sr-only">Contraseña</label>
       <input type="password" name="inputpassword" id="inputpassword" class="form-control" placeholder="Contraseña" required/>
       <button id="btnLogging" class="btn btn-lg btn-primary btn-block" type="button" onclick = "printvalue()" value="print name" >Iniciar Sesión</button>

     </form>

其中onclick =“ printvalue()”和value =“ print name”对js的调用,显示带有欢迎消息的警报。

0 个答案:

没有答案



Similar searches
    如何将使用钩子的React功能组件转换为类? jQuery将光标设置在contenteditable 翻译API是否会自动将文本内容翻译成其他语言? 如何在Godadday上使用托管网址解决bot框架模拟器中的404发布错误? Keras.fit_generator需要花费更多时间