【问题标题】:Sending data to server flask html将数据发送到服务器烧瓶 html
【发布时间】:2023-03-11 21:06:01
【问题描述】:

我正在尝试创建一个简单的复选框,将数据发送到服务器这里是我的 html 代码。

<form action="." method="POST">
<div class="checksheet">

    <input id="XML Parser" class="checkbox" type="checkbox"/>XML Parser
    <input id="Feed Parser" class="checkbox" type="checkbox"/>Feed Parser
    <input id="Text Parser" class="checkbox" type="checkbox"/>Text Parser
    <input id="Case Normalization" class="checkbox" type="checkbox"/>Case Normalization
    <input id="Stemmer" class="checkbox" type="checkbox"/>  Stemmer

</div>

<div class="submit"><input type="submit"  value="Send" name="raw_text"></div>
</form>

我想要做的与这里提出的问题非常相似:Send Data from a textbox into Flask? 但除了文本框。我有复选框。

但我收到此错误:

Not Found

The requested URL was not found on the server.

If you entered the URL manually please check your spelling and try again.

我的服务器端代码(在烧瓶中)是:

@app.route('/raw_text.html')
def home ():
    file = "sample.xml"
    contents = open(file).read()

    contents = contents.decode('utf-8')
    return render_template('raw_text.html',  contents=contents,file=file)

@app.route('/raw_text.html',methods=['POST'])
def get_data():
    print "REQUEST ",request.form()
    data = request.form['raw_text']
    print data
    return "Processed"

任何建议。 谢谢

【问题讨论】:

    标签: python html flask


    【解决方案1】:

    一些事情:

    1. 您的复选框元素需要name 属性,这是数据发送到后端时使用的属性。每个相互关联的复选框都需要有相同的name

    2. 您的 action 属性需要指向一个 URL。如果您将其发布到与表单相同的页面,则可以删除该属性。

    3. ID 不能包含空格。

    4. 要访问复选框,需要&lt;label&gt;s,

    【讨论】:

    • @Fraz 我澄清了 Burhan 的回答,希望它会被批准
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 2021-11-21
    相关资源
    最近更新 更多