将数据从HTML非输入发送到Flask [英] Sending data from a html non-input to Flask

查看:148
本文介绍了将数据从HTML非输入发送到Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将非输入数据(如列表)从html发送到Flask.

how can i send non-input data (like lists) from html to Flask.

<form action="/" method="POST"> 
  <ul class="list-group">
    <li class="list-group-item " id="">Data that i want to receive 1</li>
    <li class="list-group-item " id="">Data that i want to receive 2</li>
    <li class="list-group-item " id="">Data that i want to receive 3</li>
  </ul>
  <input name="send" type="submit" value="Send">
</form> 

with request.from我只接收python中的按钮信息,但我希望从列表中获取数据.我该怎么做才能获取列表数据?

with request.from i only receive the button informations in python, but i want the data from the list. What i have to do, that i can get the list-data?

推荐答案

当按下提交"输入时,HTML表单仅将<input>标记的值发送到远程端点.您有三个列表元素,但只有一个输入"元素-提交按钮.

HTML forms only send along <input> tagged values to the remote endpoint when a "submit" input is pressed. You have three list elements, but only one "input" element - the submit button.

尝试将要与表单一起发送的其他元素放入带有适当类型的输入"标签中,并使用名称"属性来标识如何在处理代码中提取值:

Try putting the other elements you want to be sent up with the form in "input" tags, with appropriate types, and 'name' attributes identifying how the values will be extracted in processing code:

<form action="/" method="POST"> 
<ul class="list-group">
    <li class="list-group-item">
        <select name="my_select"> <!-- *NOTE* the select field, with options in a dropdown -->
            <option value="val1">Value 1</option>
            <option value="val1">Value 2</option>
            <option value="val1">Value 3</option>
        </select>
    </li>
    <li class="list-group-item">
        <input type="text" name="data_2" placeholder="Data that I want to receive 2"></input>
    </li>
    <li class="list-group-item">
        <input type="text" name="data_3" placeholder="Data that I want to receive 3"></input>
    </li>
    <li class="list-group-item">
        <input name="send" type="submit" value="Send"></input>
    </li>
</ul>

您可能要实现列表"目标的标签是选择".选择具有选项"子项,这些子项是下拉列表中的可用选项.

The tag you're probably looking for to achieve your 'list' goal is 'select'. Select has 'option' children that are the available choices from a dropdown list.

除文本"外,还有其他输入类型;请参阅 https://www.w3schools.com/html/html_forms.asp 简要介绍HTML表单的工作原理.

There are other input types than "text"; see https://www.w3schools.com/html/html_forms.asp for a concise basic rundown of how HTML forms work.

清理了一些格式;重新阅读OP问题后,添加了占位符值,添加了列表下拉列表.

cleaned up some formatting; added placeholder value, added list dropdown after re-reading OP question.

这篇关于将数据从HTML非输入发送到Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆