发送数据到服务器烧瓶html

编程入门 行业动态 更新时间:2024-10-24 16:31:01
本文介绍了发送数据到服务器烧瓶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

有任何建议。 谢谢

解决方案

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

  • $ c> action 属性需要指向一个URL。如果您将其发布到与表单相同的页面,则可以删除该属性。 >不能包含空格。
  • 要访问复选框,需要< 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:

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

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

  • ID's cannot contain spaces.

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

  • 更多推荐

    发送数据到服务器烧瓶html

    本文发布于:2023-11-27 09:01:02,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:烧瓶   服务器   数据   html

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!