首页 > 其他分享 >Flask中根据表单中下拉框的选择跳转指定页面

Flask中根据表单中下拉框的选择跳转指定页面

时间:2023-03-08 18:46:24浏览次数:33  
标签:__ return Flask app selected 跳转 Test 下拉框

HomePage.html中存在一个表单:
注意:action不写的话,路由默认在 / 下方,则该路径下方的函数名可以随意取

<h4>Complete the Form</h4>

<form id="upload_form" method="POST" action="/upload_csv_file">
    <div class="form-group">
        <select class="custom-select" name="dropdown_box_model">
            <option selected>Select a model (Required)</option>
            <option value="1">Test 1</option>
            <option value="2">Test 2</option>
            <option value="3">Test 3</option>
        </select>
       /* or <button type="submit">Submit</button> */
    </div>
</form>

{#......#}

<input type="submit" form="upload_form" class="btn btn-block1 btn-lg btn-primary mt-4"
       value="View Results">

app.py 中的路由:

@app.route("/upload_csv_file", methods=['POST'])
def upload_csv_file():
    selected = request.form['dropdown_box_model']
    if selected == '1':
        return render_template("../test1.html")
    elif selected == '2':
        return render_template("../test2.html")

# Running the app
if __name__ == '__main__':
    app.run(debug=True)

Flask标准写法:

@app.route('/', methods=['POST'])
def jump_page():
    x = request.form['dropdown_box_model']
    if x == '1':
        return redirect(url_for('1'))
    elif x == '2':
        return redirect(url_for('2'))
    else:
        return 'Error'

标签:__,return,Flask,app,selected,跳转,Test,下拉框
From: https://www.cnblogs.com/huangkenicole/p/17195715.html

相关文章

  • ODOO通过BUTTON返回一个ACTION,跳转到一个VIEW
    可以参考Odoo采购单的右侧按钮的写法。简单讲,就是先通过xmlid获取到action_id,继而获取到action,修改action的相关信息,然后将结果返回,即可以实现跳转。 mod_obj=self......
  • UI自动化--下拉框处理和等待机制
    UI自动化--下拉框处理和等待机制一、下拉框处理:网页上的js弹出框一般有三种情况,且识别不了元素,需要使用switch_to.alert()进行跳转这时候需要先跳转到此弹窗,才能做到自动化......
  • odoo跳转页面
    odoo跳转页面总结odoo视图跳转我总结为一下几点:1.默认的封装了两个数据,不需要人工维护模型名称(封装到即将跳转的视图的context的active_model属性中)单据id(封装到即将跳......
  • 关于Android Studio的Activity的页面跳转完成
    第一种方式Intentintent=newIntent();intent.setClass(this,MainActivity3.class);startActivity(intent);第二种方式Intentintent=newIntent();intent.setClas......
  • 利用Intent跳转来实现数据传输
    代码:发送Intentintent=newIntent(this,MainActivity2.class);//创建一个新的包裹,类似sessoinBundlebundle=newBundle();intuser_id=mHelper.findid(user_nam......
  • Python Flask 之 路由和渲染模板讲解与示例演示
    目录一、概述二、路由三、渲染模板四、重定向和错误五、日志六、集成WSGI中间件一、概述Flask是一款使用Python编写的Web应用框架,其设计理念是轻量级和简单易学。......
  • Flask
    Flask参考博客1.flask的使用1.1安装pip3installflask1.2使用新建py文件从flask模块导入Flask创建flask实例启动flask(和执行py文件一样,右击run)fromflas......
  • 解决element-ui的下拉框有值却无法选中的情况
    <el-selectv-model="value"placeholder="请选择"@change="change()"><el-optionv-for="iteminoptions":key="item.value":label="item.label":value="item.va......
  • 关于有些下拉框自定义样式未生效问题
    像一些下拉框自定义类名时,在DOM树中是在body下面的,所以加/deep/和important不起作用    也就是说自定义类名有,但是类名上写的样式不起作用解决办法,在全局样式书......
  • Android intent跳转工具类
    /***进行页面跳转的工具**@authorchen.lin**/publicclassIntentUtil{privatestaticfinalStringIMAGE_TYPE="image/*";privatestaticfinalStr......