发送数据到服务器烧瓶html [英] Sending data to server flask html

查看:220
本文介绍了发送数据到服务器烧瓶html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form 

我试图创建一个简单的复选框,将数据发送到服务器。行动= 。方法= POST >
< div class =checksheet>

< input id =XML Parserclass =checkboxtype =checkbox/> XML Parser
< input id =Feed Parserclass =checkbox文本解析器
<输入id =文本解析器class =checkboxtype =checkbox/> class =checkboxtype =checkbox/> Case Normalization
< input id =Stemmerclass =checkboxtype =checkbox/> Stemmer

< / div>

< div class =submit>< input type =submitvalue =Sendname =raw_text>< / div>
< / form>

我想要做的事与此处提出的问题非常相似:
除了使用文本框..我有复选框。

但是我得到这个错误:

 未找到

在服务器上未找到请求的URL。

如果您手动输入网址,请检查您的拼写,然后重试。

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

  @ app.route('/ raw_text.html')
def home():
file =sample.xml
contents = open(file).read()
$ b $ content = content.decode('utf-8')
return render_template('raw_text.html',contents = contents,file = file)

@ app.route('/ raw_text.html',methods = ['POST'])
def get_data():
printREQUEST,request.form )
data = request.form ['raw_text']
print data
returnProcessed

有任何建议。
谢谢




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

  2. $ c> action 属性需要指向一个URL。如果您将其发布到与表单相同的页面,则可以删除该属性。 >不能包含空格。
  3. 要访问复选框,需要< label> s ,



I am trying to create a simple checkbox that sends the data to server here is my html code.

<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>

What I am trying to do is very similar to the question asked here: Send Data from a textbox into Flask? But except with the text box.. I have checkboxes.

But I get this error:

Not Found

The requested URL was not found on the server.

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

MY server side code (in flask) is:

@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"

Any suggestions. Thanks

解决方案

A few things:

  1. Your checkbox elements need a name attribute, this is what is used when the data is sent to the back end. Each checkbox that is related to each other needs to have the same name.

  2. Your action attribute needs to point to a URL. If you are posting it to the same page as the form, you can remove the attribute.

  3. ID's cannot contain spaces.

  4. To be accessible the check boxes need <label>s,

这篇关于发送数据到服务器烧瓶html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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